Compare commits
No commits in common. "6fbbe4975c18642857afbd252ce0f058803a64d5" and "5aa62f7d82208a465038d2fdf54ece8da8ca2cc9" have entirely different histories.
6fbbe4975c
...
5aa62f7d82
|
@ -4,15 +4,12 @@ import type {
|
||||||
AuthActionResponse,
|
AuthActionResponse,
|
||||||
CheckResponse,
|
CheckResponse,
|
||||||
IdentityResponse,
|
IdentityResponse,
|
||||||
OnErrorResponse,
|
OnErrorResponse
|
||||||
SuccessNotificationResponse
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
} from "@refinedev/core/dist/interfaces/bindings/auth"
|
} from "@refinedev/core/dist/interfaces/bindings/auth"
|
||||||
import {Sdk} from "@lumeweb/portal-sdk";
|
import {Sdk} from "@lumeweb/portal-sdk";
|
||||||
import type {AccountInfoResponse} from "@lumeweb/portal-sdk";
|
import type {AccountInfoResponse} from "@lumeweb/portal-sdk";
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
export type AuthFormRequest = {
|
export type AuthFormRequest = {
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
@ -34,7 +31,7 @@ export type Identity = {
|
||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdatePasswordFormRequest extends UpdatePasswordFormTypes {
|
export interface UpdatePasswordFormRequest extends UpdatePasswordFormTypes{
|
||||||
currentPassword: string;
|
currentPassword: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,39 +43,6 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
type ResponseResult = {
|
|
||||||
ret: boolean | Error;
|
|
||||||
successNotification?: SuccessNotificationResponse;
|
|
||||||
redirectToSuccess?: string;
|
|
||||||
redirectToError?: string;
|
|
||||||
successCb?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleResponse = (result: ResponseResult): AuthActionResponse => {
|
|
||||||
if (result.ret) {
|
|
||||||
if (result.ret instanceof Error) {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
error: result.ret,
|
|
||||||
redirectTo: result.redirectToError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.successCb?.();
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
successNotification: result.successNotification,
|
|
||||||
redirectTo: result.redirectToSuccess,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
redirectTo: result.redirectToError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
async login(params: AuthFormRequest): Promise<AuthActionResponse> {
|
async login(params: AuthFormRequest): Promise<AuthActionResponse> {
|
||||||
const ret = await sdk.account().login({
|
const ret = await sdk.account().login({
|
||||||
|
@ -104,13 +68,17 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
|
|
||||||
async logout(params: any): Promise<AuthActionResponse> {
|
async logout(params: any): Promise<AuthActionResponse> {
|
||||||
let ret = await sdk.account().logout();
|
let ret = await sdk.account().logout();
|
||||||
return handleResponse({ret, redirectToSuccess: "/login"});
|
return {success: ret, redirectTo: "/login"};
|
||||||
},
|
},
|
||||||
|
|
||||||
async check(params?: any): Promise<CheckResponse> {
|
async check(params?: any): Promise<CheckResponse> {
|
||||||
const ret = await sdk.account().ping();
|
const ret = await sdk.account().ping();
|
||||||
|
|
||||||
return handleResponse({ret, redirectToError: "/login", successCb: maybeSetupAuth});
|
if (ret) {
|
||||||
|
maybeSetupAuth();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {authenticated: ret, redirectTo: ret ? undefined : "/login"};
|
||||||
},
|
},
|
||||||
|
|
||||||
async onError(error: any): Promise<OnErrorResponse> {
|
async onError(error: any): Promise<OnErrorResponse> {
|
||||||
|
@ -124,7 +92,7 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
first_name: params.firstName,
|
first_name: params.firstName,
|
||||||
last_name: params.lastName,
|
last_name: params.lastName,
|
||||||
});
|
});
|
||||||
return handleResponse({ret, redirectToSuccess: "/login"});
|
return {success: ret, redirectTo: ret ? "/dashboard" : undefined};
|
||||||
},
|
},
|
||||||
|
|
||||||
async forgotPassword(params: any): Promise<AuthActionResponse> {
|
async forgotPassword(params: any): Promise<AuthActionResponse> {
|
||||||
|
@ -135,12 +103,22 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
maybeSetupAuth();
|
maybeSetupAuth();
|
||||||
const ret = await sdk.account().updatePassword(params.currentPassword, params.password as string);
|
const ret = await sdk.account().updatePassword(params.currentPassword, params.password as string);
|
||||||
|
|
||||||
return handleResponse({
|
if (ret) {
|
||||||
ret, successNotification: {
|
if (ret instanceof Error) {
|
||||||
message: "Password Updated",
|
return {
|
||||||
description: "Your password has been updated successfully.",
|
success: false,
|
||||||
|
error: ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
success: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async getPermissions(params?: Record<string, any>): Promise<AuthActionResponse> {
|
async getPermissions(params?: Record<string, any>): Promise<AuthActionResponse> {
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
import {Authenticated} from "@refinedev/core";
|
import { useGo, useIsAuthenticated } from "@refinedev/core";
|
||||||
import {Navigate} from "@remix-run/react";
|
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
return (
|
const { isLoading, data } = useIsAuthenticated();
|
||||||
<Authenticated v3LegacyAuthProviderCompatible key={"index"} loading={
|
|
||||||
<>Checking Login Status</>
|
const go = useGo();
|
||||||
}>
|
|
||||||
<Navigate to="/dashboard" replace/>
|
if (isLoading) {
|
||||||
</Authenticated>
|
return <>Checking Login Status</>;
|
||||||
)
|
}
|
||||||
|
|
||||||
|
if (data?.authenticated) {
|
||||||
|
go({ to: "/dashboard", type: "replace" });
|
||||||
|
} else {
|
||||||
|
go({ to: "/login", type: "replace" });
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>Redirecting</>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
"@conform-to/react": "^1.0.2",
|
"@conform-to/react": "^1.0.2",
|
||||||
"@conform-to/zod": "^1.0.2",
|
"@conform-to/zod": "^1.0.2",
|
||||||
"@fontsource-variable/manrope": "^5.0.19",
|
"@fontsource-variable/manrope": "^5.0.19",
|
||||||
"@lumeweb/portal-sdk": "0.0.0-20240320165911",
|
"@lumeweb/portal-sdk": "0.0.0-20240319140708",
|
||||||
"@radix-ui/react-avatar": "^1.0.4",
|
"@radix-ui/react-avatar": "^1.0.4",
|
||||||
"@radix-ui/react-checkbox": "^1.0.4",
|
"@radix-ui/react-checkbox": "^1.0.4",
|
||||||
"@radix-ui/react-dialog": "^1.0.5",
|
"@radix-ui/react-dialog": "^1.0.5",
|
||||||
|
|
Loading…
Reference in New Issue