import { reactive } from 'vue'

const tokenKey = 'supertodo_access_token'

export const session = reactive({
  token: localStorage.getItem(tokenKey) ?? '',
  email: localStorage.getItem('supertodo_email') ?? '',
})

export function setSession(token: string, email: string) {
  session.token = token
  session.email = email
  localStorage.setItem(tokenKey, token)
  localStorage.setItem('supertodo_email', email)
}

export function setSessionToken(token: string) {
  session.token = token
  localStorage.setItem(tokenKey, token)
}

export function clearSession() {
  session.token = ''
  session.email = ''
  localStorage.removeItem(tokenKey)
  localStorage.removeItem('supertodo_email')
}
