feat: support login
- migrate old API into typescript but not finished (only webLogin works now) - seperate the logger of backend due to the shitty behavior of Flask (change logging level)
This commit is contained in:
43
frontend/src/api/common.ts
Normal file
43
frontend/src/api/common.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { apiWrapper, boolApiWrapper } from './index'
|
||||
|
||||
// /**
|
||||
// * Login with salt
|
||||
// * @param username - Username
|
||||
// * @param password - Password
|
||||
// * @returns Token if login successful, undefined otherwise
|
||||
// */
|
||||
// export async function login(username: string, password: string): Promise<string | undefined> {
|
||||
// const salt: string | undefined = await apiWrapper('/api/common/salt', { username });
|
||||
// if (typeof salt === 'undefined') return undefined;
|
||||
|
||||
// const computedPassword = computePasswordWithSalt(password, salt);
|
||||
// return apiWrapper('/api/common/login', { username, password: computedPassword });
|
||||
// }
|
||||
|
||||
/**
|
||||
* Web login
|
||||
* @param username - Username
|
||||
* @param password - Password
|
||||
* @returns Token if login successful, undefined otherwise
|
||||
*/
|
||||
export async function webLogin(username: string, password: string): Promise<string | undefined> {
|
||||
return apiWrapper('/api/common/webLogin', { username, password });
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout
|
||||
* @param token - Authentication token
|
||||
* @returns true if logout successful, false otherwise if logout failed
|
||||
*/
|
||||
export async function logout(token: string): Promise<boolean> {
|
||||
return boolApiWrapper('/api/common/logout', { token });
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate token
|
||||
* @param token - Authentication token
|
||||
* @returns true if token is valid, false otherwise
|
||||
*/
|
||||
export async function tokenValid(token: string): Promise<boolean> {
|
||||
return boolApiWrapper('/api/common/tokenValid', { token });
|
||||
}
|
||||
Reference in New Issue
Block a user