generated from muhtadeetaron/nextjs-template
fix(api): fix api endpoint logic #2
This commit is contained in:
14
lib/auth.ts
14
lib/auth.ts
@ -1,4 +1,6 @@
|
||||
export const API_URL = "https://examjam-api.pptx704.com";
|
||||
import { LoginForm, RegisterForm } from "@/types/auth";
|
||||
|
||||
export const API_URL = "https://examjam-backend.omukk.dev";
|
||||
|
||||
// Cookie utility function
|
||||
const setCookie = (name: string, value: string | null, days: number = 7) => {
|
||||
@ -15,12 +17,6 @@ const setCookie = (name: string, value: string | null, days: number = 7) => {
|
||||
}
|
||||
};
|
||||
|
||||
interface AuthForm {
|
||||
email: string;
|
||||
password: string;
|
||||
[key: string]: any; // for flexibility
|
||||
}
|
||||
|
||||
type SetTokenFn = (token: string) => void;
|
||||
|
||||
// Optional: Create a custom error type to carry extra data
|
||||
@ -29,7 +25,7 @@ interface APIError extends Error {
|
||||
}
|
||||
|
||||
export const login = async (
|
||||
form: AuthForm,
|
||||
form: LoginForm,
|
||||
setToken: SetTokenFn
|
||||
): Promise<void> => {
|
||||
const response = await fetch(`${API_URL}/auth/login`, {
|
||||
@ -51,7 +47,7 @@ export const login = async (
|
||||
};
|
||||
|
||||
export const register = async (
|
||||
form: AuthForm,
|
||||
form: RegisterForm,
|
||||
setToken: SetTokenFn
|
||||
): Promise<void> => {
|
||||
const response = await fetch(`${API_URL}/auth/register`, {
|
||||
|
||||
Reference in New Issue
Block a user