File size: 1,481 Bytes
5e870e6
 
 
 
 
 
 
 
 
 
 
c4da317
5e870e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { betterAuth } from "better-auth";

// Initialize Better Auth as required
// Note: Better Auth handles JWT internally, we don't need a separate JWT plugin
export const auth = betterAuth({
  // Use JWT for session management with 7-day expiration
  session: {
    expiresIn: 7 * 24 * 60 * 60, // 7 days in seconds
    updateAge: 24 * 60 * 60, // Update session every 24 hours if active
  },
  // Configure to work with backend that sets httpOnly cookies
  baseURL: 'https://tahasaif3-ai-taskflow-backend.hf.space',
  // Do NOT store tokens in localStorage as per requirements
  // Rely on httpOnly cookies set by backend
  cookies: {
    sessionToken: {
      httpOnly: true,
      secure: process.env.NODE_ENV === "production",
      sameSite: "lax",
      path: "/",
    },
  },
  // Use email and password authentication
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: false, // For simplicity in this implementation
  },
  // Configure auth endpoints to match backend
  socialProviders: {},
  // Error handling
  dangerouslyDisplayErrors: process.env.NODE_ENV !== "production",
});

// Export auth methods as required
export const { signIn, signOut, signUp, useSession } = auth;

// Export types for frontend components
export interface User {
  id: string;
  email: string;
  name?: string;
}

export interface LoginCredentials {
  email: string;
  password: string;
}

export interface RegisterCredentials {
  email: string;
  password: string;
}