mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
get self api fn
This commit is contained in:
parent
6f9f255abf
commit
e119ae5fc4
4 changed files with 28 additions and 5 deletions
|
@ -1,15 +1,22 @@
|
|||
import {api, authMiddleware, errorMiddleware, resultMiddleware} from "~/utils/api";
|
||||
import { API } from "~/constants/api";
|
||||
import { IApiUser } from "~/redux/auth/constants";
|
||||
import {IResultWithStatus} from "~/redux/types";
|
||||
import {userLoginTransform} from "~/redux/auth/transforms";
|
||||
import {authMeTransform, userLoginTransform} from "~/redux/auth/transforms";
|
||||
import {IUser} from "~/redux/auth/types";
|
||||
|
||||
export const apiUserLogin = (
|
||||
{ username, password }:
|
||||
{ username: string, password: string }
|
||||
): Promise<IResultWithStatus<{ token: string, status?: number, user?: IApiUser }>> => (
|
||||
): Promise<IResultWithStatus<{ token: string, status?: number }>> => (
|
||||
api.post(API.USER.LOGIN, { username, password })
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware)
|
||||
.then(userLoginTransform)
|
||||
);
|
||||
|
||||
export const getAuthSelf = (): Promise<IResultWithStatus<{ user: IUser }>> => (
|
||||
api.get(API.USER.ME)
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware)
|
||||
.then(authMeTransform)
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue