35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { createAuthProvider, type BaseUser } from '@bytelyst/react-auth';
|
|
import { tradingRuntime } from './runtime';
|
|
|
|
export interface TradingAuthUser extends BaseUser {
|
|
id: string;
|
|
plan?: string;
|
|
}
|
|
|
|
export const tradingWebAuth = createAuthProvider<TradingAuthUser>({
|
|
baseUrl: tradingRuntime.platformApiUrl,
|
|
productId: tradingRuntime.productId,
|
|
storagePrefix: 'invttrdg_web',
|
|
loginEndpoint: '/auth/login',
|
|
registerEndpoint: '/auth/register',
|
|
forgotPasswordEndpoint: '/auth/forgot-password',
|
|
changePasswordEndpoint: '/auth/change-password',
|
|
deleteAccountEndpoint: '/auth/account',
|
|
refreshEndpoint: '/auth/refresh',
|
|
mapLoginResponse: (data: unknown) => {
|
|
const response = data as {
|
|
user: TradingAuthUser;
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
};
|
|
return {
|
|
user: response.user,
|
|
accessToken: response.accessToken,
|
|
refreshToken: response.refreshToken,
|
|
};
|
|
},
|
|
});
|
|
|
|
export const TradingAuthProvider = tradingWebAuth.AuthProvider;
|
|
export const useTradingAuth = tradingWebAuth.useAuth;
|