feat: implement identity api

This commit is contained in:
Derrick Hammer 2024-03-14 07:10:17 -04:00
parent 0b5e066aab
commit 5f97e8c7d8
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 33 additions and 7 deletions

View File

@ -1,9 +1,15 @@
import type {AuthProvider} from "@refinedev/core"
import type {
AuthActionResponse,
CheckResponse,
IdentityResponse,
OnErrorResponse
// @ts-ignore
import type {AuthActionResponse, CheckResponse, OnErrorResponse} from "@refinedev/core/dist/interfaces/bindings/auth"
} from "@refinedev/core/dist/interfaces/bindings/auth"
import {Sdk} from "@lumeweb/portal-sdk";
import Cookies from 'universal-cookie';
import type {AccountInfoResponse} from "@lumeweb/portal-sdk";
export type AuthFormRequest = {
email: string;
@ -19,6 +25,13 @@ export type RegisterFormRequest = {
lastName: string;
}
export type Identity = {
id: string;
firstName: string;
lastName: string;
email: string;
}
export class PortalAuthProvider implements RequiredAuthProvider {
private sdk: Sdk;
@ -118,8 +131,21 @@ export class PortalAuthProvider implements RequiredAuthProvider {
return {success: true};
}
async getIdentity(params?: any): Promise<AuthActionResponse> {
return {id: "1", fullName: "John Doe", avatar: "https://via.placeholder.com/150"};
async getIdentity(params?: Identity): Promise<IdentityResponse> {
const ret = await this.sdk.account().info();
if (!ret) {
return {identity: null};
}
const acct = ret as AccountInfoResponse;
return {
id: acct.id,
firstName: acct.first_name,
lastName: acct.last_name,
email: acct.email,
};
}
public static create(apiUrl: string): AuthProvider {