This commit is contained in:
@@ -11,9 +11,11 @@ import { useLoginWithOtp, useOtpVerify } from '../hooks/useAuthData'
|
||||
import { extractErrorMessage, setRefreshToken } from '../../../config/func'
|
||||
import { setToken } from '../../../config/func'
|
||||
import { toast } from '@/shared/toast'
|
||||
import { Paths } from '@/config/Paths'
|
||||
import { useSessionAuth } from '@/config/sessionAuth'
|
||||
import { appNavigate } from '@/config/navigation'
|
||||
import { getDefaultAdminPath } from '@/config/permissions'
|
||||
import type { BaseResponse } from '@/shared/types/Types'
|
||||
import type { OtpVerifyResponseType } from '../types/AuthTypes'
|
||||
|
||||
const LoginStep2: FC = () => {
|
||||
|
||||
@@ -39,11 +41,12 @@ const LoginStep2: FC = () => {
|
||||
otp: values.otp
|
||||
}
|
||||
otpVerify.mutate(params, {
|
||||
onSuccess(data) {
|
||||
onSuccess(data: BaseResponse<OtpVerifyResponseType>) {
|
||||
setToken(data?.data?.tokens?.accessToken?.token)
|
||||
setRefreshToken(data?.data?.tokens?.refreshToken?.token)
|
||||
useSessionAuth.getState().setAuthenticated(true)
|
||||
appNavigate(Paths.home, { replace: true })
|
||||
const permissions = data?.data?.admin?.permissions ?? []
|
||||
appNavigate(getDefaultAdminPath(permissions), { replace: true })
|
||||
},
|
||||
onError(error) {
|
||||
toast(extractErrorMessage(error), 'error')
|
||||
|
||||
@@ -33,6 +33,22 @@ export type OtpVerifyType = {
|
||||
otp: string;
|
||||
};
|
||||
|
||||
export type AdminLoginResponseType = {
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
phone: string;
|
||||
role: string;
|
||||
permissions: string[];
|
||||
};
|
||||
|
||||
export type OtpVerifyResponseType = {
|
||||
tokens: {
|
||||
accessToken: { token: string };
|
||||
refreshToken: { token: string };
|
||||
};
|
||||
admin: AdminLoginResponseType;
|
||||
};
|
||||
|
||||
export type CheckHasAccountType = {
|
||||
email: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user