Skip to content

Commit

Permalink
Force-refresh Firebase token every hour
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev committed Apr 1, 2023
1 parent 50c80de commit c2431af
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,25 @@ export default (props) => {
}

const authGet = async (path) => {
let token = state.token
if (token) {
const user = firebase.auth().currentUser
const idToken = await user.getIdToken(true) // Force refresh the token
if (idToken !== token) {
token = idToken
setState({
user: state.user,
loading: state.loading,
token: idToken,
parties: state.parties,
countries: state.countries,
organizations: state.organizations,
})
}
}
const res = await axios.get(`${apiHost}${path}`, {
headers: {
Authorization: `Bearer ${state.token}`,
Authorization: `Bearer ${token}`,
'Accept-Language': 'bg-BG',
},
})
Expand Down

0 comments on commit c2431af

Please sign in to comment.