diff --git a/packages/builder/src/stores/portal/auth.js b/packages/builder/src/stores/portal/auth.js index 2d2b455b37..71f4841053 100644 --- a/packages/builder/src/stores/portal/auth.js +++ b/packages/builder/src/stores/portal/auth.js @@ -113,11 +113,7 @@ export function createAuthStore() { }, login: async creds => { const tenantId = get(store).tenantId - await API.logIn({ - username: creds.username, - password: creds.password, - tenantId, - }) + await API.logIn(tenantId, creds.username, creds.password) await actions.getSelf() }, logout: async () => { @@ -138,18 +134,11 @@ export function createAuthStore() { }, forgotPassword: async email => { const tenantId = get(store).tenantId - await API.requestForgotPassword({ - tenantId, - email, - }) + await API.requestForgotPassword(tenantId, email) }, resetPassword: async (password, resetCode) => { const tenantId = get(store).tenantId - await API.resetPassword({ - tenantId, - password, - resetCode, - }) + await API.resetPassword(tenantId, password, resetCode) }, generateAPIKey: async () => { return API.generateAPIKey() diff --git a/packages/frontend-core/src/api/auth.js b/packages/frontend-core/src/api/auth.ts similarity index 66% rename from packages/frontend-core/src/api/auth.js rename to packages/frontend-core/src/api/auth.ts index 9289d71239..a6f8cc1fc9 100644 --- a/packages/frontend-core/src/api/auth.js +++ b/packages/frontend-core/src/api/auth.ts @@ -1,11 +1,31 @@ -export const buildAuthEndpoints = API => ({ +import { BaseAPIClient } from "./types" + +export interface AuthEndpoints { + logIn: (tenantId: string, username: string, password: string) => Promise + logOut: () => Promise<{ message: string }> + requestForgotPassword: ( + tenantId: string, + email: string + ) => Promise<{ message: string }> + resetPassword: ( + tenantId: string, + password: string, + resetCode: string + ) => Promise<{ message: string }> + + // TODO + setInitInfo: (info: any) => Promise + getInitInfo: () => Promise +} + +export const buildAuthEndpoints = (API: BaseAPIClient): AuthEndpoints => ({ /** * Performs a login request. * @param tenantId the ID of the tenant to log in to * @param username the username (email) * @param password the password */ - logIn: async ({ tenantId, username, password }) => { + logIn: async (tenantId, username, password) => { return await API.post({ url: `/api/global/auth/${tenantId}/login`, body: { @@ -49,7 +69,7 @@ export const buildAuthEndpoints = API => ({ * @param tenantId the ID of the tenant the user is in * @param email the email address of the user */ - requestForgotPassword: async ({ tenantId, email }) => { + requestForgotPassword: async (tenantId, email) => { return await API.post({ url: `/api/global/auth/${tenantId}/reset`, body: { @@ -64,7 +84,7 @@ export const buildAuthEndpoints = API => ({ * @param password the new password to set * @param resetCode the reset code to authenticate the request */ - resetPassword: async ({ tenantId, password, resetCode }) => { + resetPassword: async (tenantId, password, resetCode) => { return await API.post({ url: `/api/global/auth/${tenantId}/reset/update`, body: { diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index db8cb4578c..5df7f777c0 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -3,6 +3,7 @@ import { AnalyticsEndpoints } from "./analytics" import { AppEndpoints } from "./app" import { AttachmentEndpoints } from "./attachments" import { AuditLogsEndpoints } from "./auditLogs" +import { AuthEndpoints } from "./auth" export enum HTTPMethod { POST = "POST", @@ -50,4 +51,5 @@ export type APIClient = BaseAPIClient & AnalyticsEndpoints & AppEndpoints & AttachmentEndpoints & - AuditLogsEndpoints & { [key: string]: any } + AuditLogsEndpoints & + AuthEndpoints & { [key: string]: any }