Update auth endpoints to use TS

This commit is contained in:
Andrew Kingston 2024-11-27 11:02:16 +00:00
parent 544e3a9da4
commit 679f08dcc4
No known key found for this signature in database
3 changed files with 30 additions and 19 deletions

View File

@ -113,11 +113,7 @@ export function createAuthStore() {
}, },
login: async creds => { login: async creds => {
const tenantId = get(store).tenantId const tenantId = get(store).tenantId
await API.logIn({ await API.logIn(tenantId, creds.username, creds.password)
username: creds.username,
password: creds.password,
tenantId,
})
await actions.getSelf() await actions.getSelf()
}, },
logout: async () => { logout: async () => {
@ -138,18 +134,11 @@ export function createAuthStore() {
}, },
forgotPassword: async email => { forgotPassword: async email => {
const tenantId = get(store).tenantId const tenantId = get(store).tenantId
await API.requestForgotPassword({ await API.requestForgotPassword(tenantId, email)
tenantId,
email,
})
}, },
resetPassword: async (password, resetCode) => { resetPassword: async (password, resetCode) => {
const tenantId = get(store).tenantId const tenantId = get(store).tenantId
await API.resetPassword({ await API.resetPassword(tenantId, password, resetCode)
tenantId,
password,
resetCode,
})
}, },
generateAPIKey: async () => { generateAPIKey: async () => {
return API.generateAPIKey() return API.generateAPIKey()

View File

@ -1,11 +1,31 @@
export const buildAuthEndpoints = API => ({ import { BaseAPIClient } from "./types"
export interface AuthEndpoints {
logIn: (tenantId: string, username: string, password: string) => Promise<void>
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<void>
getInitInfo: () => Promise<any>
}
export const buildAuthEndpoints = (API: BaseAPIClient): AuthEndpoints => ({
/** /**
* Performs a login request. * Performs a login request.
* @param tenantId the ID of the tenant to log in to * @param tenantId the ID of the tenant to log in to
* @param username the username (email) * @param username the username (email)
* @param password the password * @param password the password
*/ */
logIn: async ({ tenantId, username, password }) => { logIn: async (tenantId, username, password) => {
return await API.post({ return await API.post({
url: `/api/global/auth/${tenantId}/login`, url: `/api/global/auth/${tenantId}/login`,
body: { body: {
@ -49,7 +69,7 @@ export const buildAuthEndpoints = API => ({
* @param tenantId the ID of the tenant the user is in * @param tenantId the ID of the tenant the user is in
* @param email the email address of the user * @param email the email address of the user
*/ */
requestForgotPassword: async ({ tenantId, email }) => { requestForgotPassword: async (tenantId, email) => {
return await API.post({ return await API.post({
url: `/api/global/auth/${tenantId}/reset`, url: `/api/global/auth/${tenantId}/reset`,
body: { body: {
@ -64,7 +84,7 @@ export const buildAuthEndpoints = API => ({
* @param password the new password to set * @param password the new password to set
* @param resetCode the reset code to authenticate the request * @param resetCode the reset code to authenticate the request
*/ */
resetPassword: async ({ tenantId, password, resetCode }) => { resetPassword: async (tenantId, password, resetCode) => {
return await API.post({ return await API.post({
url: `/api/global/auth/${tenantId}/reset/update`, url: `/api/global/auth/${tenantId}/reset/update`,
body: { body: {

View File

@ -3,6 +3,7 @@ import { AnalyticsEndpoints } from "./analytics"
import { AppEndpoints } from "./app" import { AppEndpoints } from "./app"
import { AttachmentEndpoints } from "./attachments" import { AttachmentEndpoints } from "./attachments"
import { AuditLogsEndpoints } from "./auditLogs" import { AuditLogsEndpoints } from "./auditLogs"
import { AuthEndpoints } from "./auth"
export enum HTTPMethod { export enum HTTPMethod {
POST = "POST", POST = "POST",
@ -50,4 +51,5 @@ export type APIClient = BaseAPIClient &
AnalyticsEndpoints & AnalyticsEndpoints &
AppEndpoints & AppEndpoints &
AttachmentEndpoints & AttachmentEndpoints &
AuditLogsEndpoints & { [key: string]: any } AuditLogsEndpoints &
AuthEndpoints & { [key: string]: any }