fix(site): Fix login flow (#6294)

This commit is contained in:
Bruno Quaresma
2023-02-23 15:25:12 +00:00
committed by GitHub
parent a32169ccb5
commit 8298a924f6
15 changed files with 276 additions and 389 deletions
+13 -3
View File
@@ -101,9 +101,19 @@ export const logout = async (): Promise<void> => {
await axios.post("/api/v2/users/logout")
}
export const getUser = async (): Promise<TypesGen.User> => {
const response = await axios.get<TypesGen.User>("/api/v2/users/me")
return response.data
export const getAuthenticatedUser = async (): Promise<
TypesGen.User | undefined
> => {
try {
const response = await axios.get<TypesGen.User>("/api/v2/users/me")
return response.data
} catch (error) {
if (axios.isAxiosError(error) && error.response?.status === 401) {
return undefined
}
throw error
}
}
export const getAuthMethods = async (): Promise<TypesGen.AuthMethods> => {