Skip to content

Commit

Permalink
feat: catch /me error to rm auth
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSlain committed Nov 27, 2024
1 parent 0fdf99e commit 7f614d9
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/utils/manageConnexion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@ export const setUserInfos = async (
setUserAuth: Dispatch<SetStateAction<UserAuth>>,
userUrl: string,
) => {
const userInfos = await useFetch(userUrl, 'GET', {
headers: {
Authorization: `Bearer ${token}`,
},
data: null,
})

if (userInfos.detail === 'Unauthorized') return rmAuth()

storeAuth(token)

if (token !== 'null')
return setUserAuth({
email: userInfos.email,
username: userInfos.username,
// TODO: see if we cand delete userAuth.authToken
authToken: token,
isLogin: true,
try {
const userInfos = await useFetch(userUrl, 'GET', {
headers: {
Authorization: `Bearer ${token}`,
},
data: null,
})
if (userInfos.detail === 'Unauthorized') return rmAuth()

storeAuth(token)

if (token !== 'null')
return setUserAuth({
email: userInfos.email,
username: userInfos.username,
// TODO: see if we cand delete userAuth.authToken
authToken: token,
isLogin: true,
})
} catch (error) {
console.error('error', error)
rmAuth()
}
return setUserAuth(InitialUserAuth)
}

Expand Down

0 comments on commit 7f614d9

Please sign in to comment.