fix: perform logout if the silent refresh attempt fails (#3705)
Co-authored-by: Dmitry Mukovkin <d.mukovkin@cft.ru> Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
This commit is contained in:
@@ -114,6 +114,7 @@ async function setInitialUser() {
|
|||||||
} else {
|
} else {
|
||||||
setUser(null)
|
setUser(null)
|
||||||
isGettingInitialUser.value = false
|
isGettingInitialUser.value = false
|
||||||
|
await logout()
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -146,22 +147,26 @@ async function setInitialUser() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function refreshToken() {
|
async function refreshToken() {
|
||||||
const res = await axios.get(
|
try {
|
||||||
`${import.meta.env.VITE_BACKEND_API_URL}/auth/refresh`,
|
const res = await axios.get(
|
||||||
{
|
`${import.meta.env.VITE_BACKEND_API_URL}/auth/refresh`,
|
||||||
withCredentials: true,
|
{
|
||||||
|
withCredentials: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const isSuccessful = res.status === 200
|
||||||
|
|
||||||
|
if (isSuccessful) {
|
||||||
|
authEvents$.next({
|
||||||
|
event: "token_refresh",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
const isSuccessful = res.status === 200
|
return isSuccessful
|
||||||
|
} catch (error) {
|
||||||
if (isSuccessful) {
|
return false
|
||||||
authEvents$.next({
|
|
||||||
event: "token_refresh",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return isSuccessful
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendMagicLink(email: string) {
|
async function sendMagicLink(email: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user