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 => {
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()

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.
* @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: {

View File

@ -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 }