forked from amand33p/bug-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
35 lines (26 loc) · 734 Bytes
/
Copy pathauth.ts
File metadata and controls
35 lines (26 loc) · 734 Bytes
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
import axios from 'axios';
import backendUrl from '../backendUrl';
interface Credentials {
username: string;
password: string;
}
type Token = string | null;
let token: Token = null;
const setToken = (newToken: string) => {
token = newToken;
};
export const setConfig = () => {
return {
headers: { 'x-auth-token': token },
};
};
const login = async (credentials: Credentials) => {
const response = await axios.post(`${backendUrl}/login`, credentials);
return response.data;
};
const signup = async (credentials: Credentials) => {
const response = await axios.post(`${backendUrl}/signup`, credentials);
return response.data;
};
const authService = { login, signup, setToken };
export default authService;