import type { AuthUser } from "../types";

let token = localStorage.getItem("token") ?? "";
let currentUser: AuthUser | null = null;

export function getToken() {
  return token;
}

export function getCurrentUser() {
  return currentUser;
}

export function setSession(nextToken: string, user: AuthUser) {
  token = nextToken;
  currentUser = user;
  localStorage.setItem("token", nextToken);
}

export function setCurrentUser(user: AuthUser) {
  currentUser = user;
}

export function clearSession() {
  token = "";
  currentUser = null;
  localStorage.removeItem("token");
}

