-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EDIT feature/login catch 401 but refresh token not complete
- Loading branch information
Showing
6 changed files
with
107 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,57 @@ | ||
import Api from './api' | ||
import { getToken } from './apiAuth' | ||
import { refresh ,getToken } from './apiAuth' | ||
|
||
export async function getAll() { | ||
let api = await Api.get('/problems/', {Authorization: `Bearer ${await getToken()}`}) | ||
let api | ||
try { | ||
api = await Api.get('/problems/', {Authorization: `Bearer ${await getToken()}`}) | ||
} | ||
catch (error) { | ||
if(error.status == 401) { | ||
await refresh() | ||
api = await Api.get('/problems/', {Authorization: `Bearer ${await getToken()}`}) | ||
} | ||
} | ||
return api.data | ||
} | ||
|
||
export async function get(id) { | ||
let api = await Api.get(`/problems/${id}`, {Authorization: `Bearer ${await getToken()}`}) | ||
let api | ||
try { | ||
api = await Api.get(`/problems/${id}`, {Authorization: `Bearer ${await getToken()}`}) | ||
} | ||
catch (error) { | ||
if(error.status == 401) { | ||
await refresh() | ||
api = await Api.get(`/problems/${id}`, {Authorization: `Bearer ${await getToken()}`}) | ||
} | ||
} | ||
return api.data | ||
} | ||
|
||
export async function post(data) { | ||
let api = await Api.post('/problems/', data, {Authorization: `Bearer ${await getToken()}`}) | ||
let api | ||
try { | ||
api = await Api.post('/problems/', data, {Authorization: `Bearer ${await getToken()}`}) | ||
} | ||
catch (error) { | ||
if(error.status == 401) { | ||
await refresh() | ||
api = await Api.post('/problems/', data, {Authorization: `Bearer ${await getToken()}`}) | ||
} | ||
} | ||
return api.data | ||
} | ||
|
||
export async function put(id, data) { | ||
let api = await Api.put(`/problems/${id}`, data, {Authorization: `Bearer ${await getToken()}`}) | ||
let api | ||
try { | ||
api = await Api.put(`/problems/${id}`, data, {Authorization: `Bearer ${await getToken()}`}) | ||
} catch (error) { | ||
if(error.status == 401) { | ||
await refresh() | ||
api = await Api.put(`/problems/${id}`, data, {Authorization: `Bearer ${await getToken()}`}) | ||
} | ||
} | ||
return api.data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import Api from './api' | ||
import { getToken } from './apiAuth' | ||
import { refresh, getToken } from './apiAuth' | ||
|
||
export async function getAll() { | ||
let api = await Api.get('/problemtypes/', {Authorization: `Bearer ${await getToken()}`}) | ||
let api | ||
try { | ||
api = await Api.get('/problemtypes/', {Authorization: `Bearer ${await getToken()}`}) | ||
} | ||
catch (error) { | ||
if(error.status == 401) { | ||
console.log('in error 401') | ||
await refresh() | ||
api = await Api.get('/problemtypes/', {Authorization: `Bearer ${await getToken()}`}) | ||
} | ||
} | ||
return api.data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters