fix link token

This commit is contained in:
Nguyễn Hải Dũng
2022-12-21 14:26:16 +07:00
parent 12daa7b687
commit 58ebf27cf1
4 changed files with 35 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ import React, { Component } from 'react';
import "react-datepicker/dist/react-datepicker.css";
import { HOST } from '../../config/index';
import Store from '../../store';
import { role } from '../../actions/role';
class AutoLogin extends Component {
constructor(props) {
super(props);
@@ -24,11 +25,30 @@ class AutoLogin extends Component {
if(this.props.match.params.token){
localStorage.setItem("access_token", "Bearer " + this.props.match.params.token);
Store.dispatch(login("Bearer " + this.props.match.params.token));
window.location.href = "/";
let data = fetch(`${HOST}/api/get_info`, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': this.props.match.params.token,
// 'Authorization': token,
},
}).then((response) => {
return response.json()
}).then((data) => {
if(data.status === 10000){
localStorage.setItem("roles", JSON.stringify(data.roles));
Store.dispatch(role(data.roles));
window.location.href = "/";
}else{
alert('Sai token!!!');
window.location.href = "/login";
}
})
}
}
render() {
console.log('oke',this.props.match)
console.log('oke',Store.getState().role.role)
return(
<div></div>
)