accountService.ts
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { createApiClient } from "../lib/apiClient";
import { setTokens } from "../lib/authStorage";
export type AccountLoginInput = {
userName: string;
password: string;
uuid?: string | null;
code?: string | null;
};
export type AccountLoginOutput = {
token: string;
refreshToken?: string | null;
};
const api = createApiClient();
/**
* ABP conventional: POST /api/app/account/login
* (matches backend method name PostLoginAsync)
*/
export async function login(input: AccountLoginInput): Promise<AccountLoginOutput> {
const raw = await api.requestJson<any>({
path: "/account/login",
method: "POST",
body: {
userName: input.userName,
password: input.password,
uuid: input.uuid ?? null,
code: input.code ?? null,
},
});
const token = String(raw?.token ?? raw?.Token ?? "");
if (!token) throw new Error("Sign-in failed: no token was returned.");
const refreshToken = (raw?.refreshToken ?? raw?.RefreshToken ?? null) as string | null;
setTokens({ token, refreshToken });
return { token, refreshToken };
}