forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth-service.ts
More file actions
53 lines (47 loc) · 1.19 KB
/
Copy pathauth-service.ts
File metadata and controls
53 lines (47 loc) · 1.19 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
42
43
44
45
46
47
48
49
50
51
52
53
import { apiClient, extractApiErrorMessage } from '@/lib/api-client';
export interface NonceResponse {
nonce: string;
expiresAt: number;
}
export interface VerifyResponse {
accessToken: string;
}
export interface MeResponse {
id: string;
publicKey: string;
createdAt: string;
}
export const AuthService = {
async requestChallenge(publicKey: string): Promise<NonceResponse> {
try {
const response = await apiClient.post<NonceResponse>('/auth/nonce', {
publicKey,
});
return response.data;
} catch (error) {
throw new Error(extractApiErrorMessage(error));
}
},
async verifySignature(
publicKey: string,
signedNonce: string,
): Promise<VerifyResponse> {
try {
const response = await apiClient.post<VerifyResponse>('/auth/verify', {
publicKey,
signedNonce,
});
return response.data;
} catch (error) {
throw new Error(extractApiErrorMessage(error));
}
},
async getMe(): Promise<MeResponse> {
try {
const response = await apiClient.get<MeResponse>('/auth/me');
return response.data;
} catch (error) {
throw new Error(extractApiErrorMessage(error));
}
},
};