Skip to content
Snippets Groups Projects
Commit 7a6793b9 authored by Lucas Eduardo Schoenfelder's avatar Lucas Eduardo Schoenfelder
Browse files

fixed white screen on redirect bug

parent 57c8c751
No related branches found
No related tags found
4 merge requests!57Merge of develop into master,!56Fixed buttons reportar, seguir, compartilhar, guardar and entrar (in comments...,!39Update admin system,!35Fix remaining bugs
......@@ -25,7 +25,7 @@ import { Store } from '../Store';
import ColaborarModal from './ColaborarModal.js'
import Snackbar from '@material-ui/core/Snackbar';
import MuiAlert from '@material-ui/lab/Alert';
import { useLocation } from 'react-router-dom'
import { useLocation, useHistory } from 'react-router-dom'
import MenuBarMobile from './MenuBarMobile.js'
import {validateGoogleLoginToken} from './HelperFunctions/getAxiosConfig'
......@@ -63,7 +63,10 @@ export default function Header(props){
}, [])*/
let loc = useLocation()
let history = useHistory()
useEffect(() => {
const url = `/auth/validate_token/`
let query = new URLSearchParams(loc.search)
if(query.get("auth_token")) {
......@@ -76,8 +79,8 @@ export default function Header(props){
"token-type" : 'Bearer'
}
}
validateGoogleLoginToken(config, handleSuccessValidateToken, (error) => {console.log(error)})
redirect()
validateGoogleLoginToken(url, config, handleSuccessValidateToken, (error) => {console.log(error)})
history.push("/")
}
}, [loc])
......@@ -90,10 +93,6 @@ export default function Header(props){
}
}, [state.currentUser.askTeacherQuestion])
const redirect = () => {
props.history.push('/')
}
const toggleSnackbar = (event, reason) => {
if (reason === 'clickaway') {
return;
......
......@@ -196,20 +196,33 @@ export const fetchAllRequest = (urls, onSuccess, onError) => {
})
}
export const validateGoogleLoginToken = (config, onSuccess, onError) => {
axios.get( (`${apiUrl}/auth/validate_token/`), config ).then(
(response) => {
if ( response.headers['access-token'] ) {
updateHeaders(response.headers)
export const validateGoogleLoginToken = (url, config, onSuccess, onError) => {
fetch((`${apiUrl}${url}`), {
method : 'POST',
headers : JSON.stringify(config)
})
.then(response => {
const auth_headers = {
client: response.headers.get('client'),
"access-token": response.headers.get('access-token'),
uid: response.headers.get('uid'),
expiry: response.headers.get('expiry'),
"token-type": "Bearer"
}
onSuccess(response.data)
},
(error) => {
sessionStorage.setItem('@portalmec/auth_headers', JSON.stringify(auth_headers))
return response.json().catch(err => {
return {};
})
})
.then(data => {
console.log(data)
onSuccess(data)
})
.catch(error => {
onError(error)
}
)
})
}
export const authentication = (url, payload, onSuccess, onError) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment