import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';

export const authCookieName = 'wa_session';
export const refreshCookieName = 'wa_refresh';
export const twoFactorChallengeCookieName = 'wa_2fa_challenge';
export const twoFactorEmailCookieName = 'wa_2fa_email';

export async function getAuthToken() {
  const cookieStore = await cookies();
  return cookieStore.get(authCookieName)?.value;
}

export async function requireAuthToken() {
  const token = await getAuthToken();
  if (!token) {
    redirect('/login');
  }

  return token;
}
