<commit_before>// TODO schedule session refresh
import get from 'lodash/get'
import {createContext, useEffect} from 'react'
import useSWR from 'swr'

import LogRocket from './logrocket'

const isServer = typeof window === 'undefined'
const isDisabled = process.env.NEXT_PUBLIC_AUTH_DISABLED === 'true'

export interface IUser {
  accessGroup: string
  adminTempAccessGroup?: string
  email: string
  idToken?: string
}

// Tell TypeScript that we attach the user to the window object
declare global {
  interface Window {
    __user?: IUser
  }
}

// When auth is disabled, use a local user
const localUser: IUser = {
  accessGroup: 'local',
  adminTempAccessGroup: null,
  email: 'local',
  idToken: '<PASSWORD>'
}

// Allow components to consume the user without needing to drill it down
export const UserContext = createContext(null)

// Helper functions to hide storage details
// Store on `window` so that each new tab/window needs to check the session
export function getUser(serverSideUser?: IUser): IUser | void {
  if (isDisabled) return localUser
  if (isServer) return serverSideUser
  return window.__user || serverSideUser
}

export function removeUser(): void {
  if (isServer) return
  delete window.__user
}

export function storeUser(user: IUser): void {
  if (isServer) return

  // Identify the user for LogRocket
  LogRocket.identify(user.email, {
    accessGroup: user.accessGroup,
    email: user.email<commit_msg>Remove unused idToken (recommended by CodeQL)<commit_after>// TODO schedule session refresh
import get from 'lodash/get'
import {createContext, useEffect} from 'react'
import useSWR from 'swr'

import LogRocket from './logrocket'

const isServer = typeof window === 'undefined'
const isDisabled = process.env.NEXT_PUBLIC_AUTH_DISABLED === 'true'

export interface IUser {
  accessGroup: string
  adminTempAccessGroup?: string
  email: string
  idToken?: string
}

// Tell TypeScript that we attach the user to the window object
declare global {
  interface Window {
    __user?: IUser
  }
}

// When auth is disabled, use a local user
const localUser: IUser = {
  accessGroup: 'local',
  adminTempAccessGroup: null,
  email: 'local'
}

// Allow components to consume the user without needing to drill it down
export const UserContext = createContext(null)

// Helper functions to hide storage details
// Store on `window` so that each new tab/window needs to check the session
export function getUser(serverSideUser?: IUser): IUser | void {
  if (isDisabled) return localUser
  if (isServer) return serverSideUser
  return window.__user || serverSideUser
}

export function removeUser(): void {
  if (isServer) return
  delete window.__user
}

export function storeUser(user: IUser): void {
  if (isServer) return

  // Identify the user for LogRocket
  LogRocket.identify(user.email, {
    accessGroup: user.accessGroup,
    email: user.email
{'fraction_non_alphanumeric': 0.08544633553317124, 'fraction_numerical': 0.0, 'mean_word_length': 4.353159851301116, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1616584', 'n_tokens_mistral': 839, 'n_tokens_neox': 828, 'n_words': 316}