|
1 |
| -import { AsyncStorage } from "react-native"; |
| 1 | +import {AsyncStorage} from "react-native"; |
2 | 2 | import config from '../config/config';
|
3 | 3 |
|
4 | 4 | let USER_TOKEN = "";
|
5 | 5 | let USER_REFRESH_TOKEN = "";
|
6 | 6 | let USER_ID = "";
|
7 | 7 |
|
8 | 8 | export async function getToken(values) {
|
| 9 | + console.log(config); |
| 10 | + return await |
9 | 11 |
|
10 |
| - let token = await |
11 |
| - |
12 |
| - fetch(``+config.API_URL+`/api/login_check`, { |
13 |
| - |
14 |
| - method: 'POST', |
15 |
| - headers: { |
16 |
| - Accept: 'application/json', |
17 |
| - 'Content-Type': 'application/json', |
18 |
| - }, |
19 |
| - body: JSON.stringify({ |
20 |
| - "username": values.email, |
21 |
| - "password": values.password, |
22 |
| - }) |
23 |
| - }) |
24 |
| - .then(async resp => { |
25 |
| - |
26 |
| - return resp.json() |
27 |
| - }) |
28 |
| - .then(async responseData => { |
29 |
| - |
30 |
| - if (responseData.token) { |
31 |
| - let id = await fetch(``+config.API_URL+`/users/check/` + values.email, { |
| 12 | + fetch(`` + config.API_URL + `/api/login_check`, { |
32 | 13 |
|
33 | 14 | method: 'POST',
|
34 | 15 | headers: {
|
35 |
| - Accept: 'application/json', |
36 |
| - 'Content-Type': 'application/json', |
37 |
| - } |
38 |
| - }) |
39 |
| - .then(async resp => { |
40 |
| - |
41 |
| - return resp.json() |
42 |
| - }) |
43 |
| - .then(async responseData => { |
44 |
| - return responseData.id |
45 |
| - }) |
46 |
| - |
47 |
| - USER_ID = await id |
48 |
| - USER_TOKEN = await responseData.token |
49 |
| - USER_REFRESH_TOKEN = await responseData.refresh_token |
50 |
| - |
51 |
| - await onSignIn() |
52 |
| - return 200 |
53 |
| - } |
54 |
| - else if (responseData.code === 401) { |
55 |
| - return 401 |
56 |
| - } |
57 |
| - else if (responseData.code === 500) { |
58 |
| - return 500 |
59 |
| - } |
60 |
| - |
61 |
| - }) |
62 |
| - .catch(err => { |
63 |
| - console.log(err) |
64 |
| - }) |
65 |
| - |
66 |
| - return token |
| 16 | + Accept: 'application/json', |
| 17 | + 'Content-Type': 'application/json', |
| 18 | + }, |
| 19 | + body: JSON.stringify({ |
| 20 | + "username": values.email, |
| 21 | + "password": values.password, |
| 22 | + }) |
| 23 | + }) |
| 24 | + .then(async resp => { |
| 25 | + |
| 26 | + return resp.json() |
| 27 | + }) |
| 28 | + .then(async responseData => { |
| 29 | + |
| 30 | + if (responseData.token) { |
| 31 | + let id = await fetch(`` + config.API_URL + `/users/check/` + values.email, { |
| 32 | + |
| 33 | + method: 'POST', |
| 34 | + headers: { |
| 35 | + Accept: 'application/json', |
| 36 | + 'Content-Type': 'application/json', |
| 37 | + } |
| 38 | + }) |
| 39 | + .then(async resp => { |
| 40 | + |
| 41 | + return resp.json() |
| 42 | + }) |
| 43 | + .then(async responseData => { |
| 44 | + return responseData.id |
| 45 | + }) |
| 46 | + |
| 47 | + USER_ID = await id |
| 48 | + USER_TOKEN = await responseData.token |
| 49 | + USER_REFRESH_TOKEN = await responseData.refresh_token |
| 50 | + |
| 51 | + await onSignIn() |
| 52 | + return 200 |
| 53 | + } else if (responseData.code === 401) { |
| 54 | + return 401 |
| 55 | + } else if (responseData.code === 500) { |
| 56 | + return 500 |
| 57 | + } |
| 58 | + |
| 59 | + }) |
| 60 | + .catch(err => { |
| 61 | + console.log(err) |
| 62 | + }) |
67 | 63 | }
|
68 | 64 |
|
69 | 65 | export const onSignIn = async () => {
|
|
0 commit comments