refactor: migrate authentication from Supabase to Better Auth and update Prisma schema models
This commit is contained in:
@@ -29,11 +29,16 @@ import type {
|
||||
UserProfileResponse,
|
||||
} from '@repo/api-contract';
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import { createAuthClient } from "better-auth/react";
|
||||
|
||||
const apiBaseUrl =
|
||||
import.meta.env.VITE_API_BASE_URL?.trim() ||
|
||||
(import.meta.env.DEV ? 'http://localhost:3000' : window.location.origin);
|
||||
let accessToken: string | null = null;
|
||||
|
||||
export const authClient = createAuthClient({
|
||||
baseURL: apiBaseUrl,
|
||||
});
|
||||
|
||||
|
||||
export class ApiClientError extends Error {
|
||||
status?: number;
|
||||
@@ -104,14 +109,6 @@ function normalizeError(error: unknown): ApiClientError {
|
||||
});
|
||||
}
|
||||
|
||||
http.interceptors.request.use((config) => {
|
||||
if (!accessToken) return config;
|
||||
|
||||
config.headers = config.headers ?? {};
|
||||
config.headers.Authorization = `Bearer ${accessToken}`;
|
||||
return config;
|
||||
});
|
||||
|
||||
http.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error: AxiosError) => {
|
||||
@@ -289,5 +286,5 @@ export function configureApiClient(nextHandlers: ErrorHandlers) {
|
||||
}
|
||||
|
||||
export function setApiAccessToken(token: string | null) {
|
||||
accessToken = token;
|
||||
// accessToken = token;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user