Spaces:
Sleeping
Sleeping
Download apps/dsa-web/src/api/auth.ts from derrickliu/stock_analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/derrickliu/stock_analysis/resolve/main/apps/dsa-web/src/api/auth.ts
- Command line
-
hf download hf://spaces/derrickliu/stock_analysis/apps/dsa-web/src/api/auth.ts
-
curl -L -o auth.ts https://huggingface.co/spaces/derrickliu/stock_analysis/resolve/main/apps/dsa-web/src/api/auth.ts
1.79 kB
| import apiClient from './index'; | |
| export type AuthStatusResponse = { | |
| authEnabled: boolean; | |
| loggedIn: boolean; | |
| passwordSet?: boolean; | |
| passwordChangeable?: boolean; | |
| setupState: 'enabled' | 'password_retained' | 'no_password'; | |
| }; | |
| export const authApi = { | |
| async getStatus(): Promise<AuthStatusResponse> { | |
| const { data } = await apiClient.get<AuthStatusResponse>('/api/v1/auth/status'); | |
| return data; | |
| }, | |
| async updateSettings( | |
| authEnabled: boolean, | |
| password?: string, | |
| passwordConfirm?: string, | |
| currentPassword?: string | |
| ): Promise<AuthStatusResponse> { | |
| const body: { | |
| authEnabled: boolean; | |
| password?: string; | |
| passwordConfirm?: string; | |
| currentPassword?: string; | |
| } = { authEnabled }; | |
| if (password !== undefined) { | |
| body.password = password; | |
| } | |
| if (passwordConfirm !== undefined) { | |
| body.passwordConfirm = passwordConfirm; | |
| } | |
| if (currentPassword !== undefined) { | |
| body.currentPassword = currentPassword; | |
| } | |
| const { data } = await apiClient.post<AuthStatusResponse>('/api/v1/auth/settings', body); | |
| return data; | |
| }, | |
| async login(password: string, passwordConfirm?: string): Promise<void> { | |
| const body: { password: string; passwordConfirm?: string } = { password }; | |
| if (passwordConfirm !== undefined) { | |
| body.passwordConfirm = passwordConfirm; | |
| } | |
| await apiClient.post('/api/v1/auth/login', body); | |
| }, | |
| async changePassword( | |
| currentPassword: string, | |
| newPassword: string, | |
| newPasswordConfirm: string | |
| ): Promise<void> { | |
| await apiClient.post('/api/v1/auth/change-password', { | |
| currentPassword, | |
| newPassword, | |
| newPasswordConfirm, | |
| }); | |
| }, | |
| async logout(): Promise<void> { | |
| await apiClient.post('/api/v1/auth/logout'); | |
| }, | |
| }; | |