-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: auto login and logout functionality (#3629)
* Made auto login not call refresh * Fixed mutation query * Removed navigation to login on logout function * Made refresh token set cookie for docker * Added return to login with custom navigate and added check for refreshing only if its authenticated * Minor refactor * Navigate after logout on get autologin * Removed unused console.log
- Loading branch information
1 parent
b699adf
commit 90d9e69
Showing
7 changed files
with
49 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 19 additions & 12 deletions
31
src/frontend/src/controllers/API/queries/auth/use-post-refresh-access.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
import { LoginType, changeUser, useMutationFunctionType } from "@/types/api"; | ||
import { UseMutationResult } from "@tanstack/react-query"; | ||
import { LANGFLOW_REFRESH_TOKEN } from "@/constants/constants"; | ||
import { useMutationFunctionType } from "@/types/api"; | ||
import { Cookies } from "react-cookie"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
interface IRefreshAccessToken { | ||
access_token: string; | ||
refresh_token: string; | ||
token_type: string; | ||
} | ||
|
||
export const useRefreshAccessToken: useMutationFunctionType<undefined, any> = ( | ||
options?, | ||
) => { | ||
export const useRefreshAccessToken: useMutationFunctionType< | ||
undefined, | ||
undefined | void, | ||
IRefreshAccessToken | ||
> = (options?) => { | ||
const { mutate } = UseRequestProcessor(); | ||
const cookies = new Cookies(); | ||
|
||
async function refreshAccess(): Promise<IRefreshAccessToken> { | ||
const res = await api.post<IRefreshAccessToken>(`${getURL("REFRESH")}`); | ||
cookies.set(LANGFLOW_REFRESH_TOKEN, res.data.refresh_token, { path: "/" }); | ||
|
||
async function refreshAccess(): Promise<any> { | ||
const res = await api.post(`${getURL("REFRESH")}`); | ||
return res.data; | ||
} | ||
|
||
const mutation: UseMutationResult = mutate( | ||
["useRefreshAccessToken"], | ||
refreshAccess, | ||
options, | ||
); | ||
const mutation = mutate(["useRefreshAccessToken"], refreshAccess, options); | ||
|
||
return mutation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters