Answer the question
In order to leave comments, you need to log in
How to make requests go after setting the token?
Tell me how to make requests go after setting the token?
This code just gets the token and sets it to the axios settings
getAuthToken(uuid: any) {
return instance.post(`/account/auth_token?deviceId=${uuid}`, {
headers: {'Accept': 'text/plain'},
})
.then(res => instance.defaults.headers.common['Authorization'] = `Bearer ${res.data}`)
.catch(e => console.log(e));
},
class App extends PureComponent<IAppProps> {
componentDidMount(): any {
console.log(this.props);
this.props.getToken();
}
render() {
return (
<div className="App">
<Route component={IntroSlider} path="/changePath" exact/>
<Route component={BeginningWork} path="/start"/>
<Route component={Work} path="/"/>
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
I don't see if you are using context or redux.
Set the isAuthorized flag and draw a component that makes requests only if this flag is set, then it will be possible to send requests to componentDidMount, or draw and check whether this flag is set when mounting or updating properties.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question