-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathgateway.js
45 lines (35 loc) · 1.39 KB
/
gateway.js
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
import { JsonServiceClient, GetNavItems } from "@servicestack/client";
import { Hello, GetLinks, GetPost, Authenticate } from "./dtos";
export const client = new JsonServiceClient("/");
client.bearerToken = localStorage.getItem('bearerToken');
export const getNav = async () => await client.get(new GetNavItems());
export const checkAuth = async () => {
try {
return await client.post(new Authenticate());
} catch (e) {
return null;
}
};
export const auth = async (request) => {
localStorage.setItem('bearerToken', null);
const response = await client.post(request);
localStorage.setItem('bearerToken', client.bearerToken = response.bearerToken);
return response;
}
export const register = async (request) => {
localStorage.setItem('bearerToken', null);
const response = await client.post(request);
localStorage.setItem('bearerToken', client.bearerToken = response.bearerToken);
return response;
}
export const signout = async () => {
localStorage.setItem('bearerToken', null);
await client.post(new Authenticate({ provider: 'logout' }));
};
export const hello = async (name) => (await client.get(new Hello({ name }))).result;
export const getLinks = async () => (await client.get(new GetLinks())).results;
export const getPost = async (id) => {
const request = new GetPost();
request.id = id;
return await client.get(request)
}