From 40138e68e8d2e08b4ed56eed04bbb2285fcd7e0d Mon Sep 17 00:00:00 2001 From: Michael van Tellingen Date: Fri, 29 Nov 2024 17:09:30 +0100 Subject: [PATCH] fix: Split GraphQL endpoint for refresh vs logout The refresh token endpoint should be different then the logut --- .changeset/sixty-ducks-learn.md | 5 +++++ packages/react/src/provider.tsx | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changeset/sixty-ducks-learn.md diff --git a/.changeset/sixty-ducks-learn.md b/.changeset/sixty-ducks-learn.md new file mode 100644 index 0000000..4b13389 --- /dev/null +++ b/.changeset/sixty-ducks-learn.md @@ -0,0 +1,5 @@ +--- +"@labdigital/federated-token-react": minor +--- + +Split GraphQL endpoint for refresh vs logout diff --git a/packages/react/src/provider.tsx b/packages/react/src/provider.tsx index f95147e..a3b965f 100644 --- a/packages/react/src/provider.tsx +++ b/packages/react/src/provider.tsx @@ -56,8 +56,9 @@ type AuthContextType = { const AuthContext = createContext(undefined); export type AuthProviderProps = { - authEndpoint: string; + refreshTokenEndpoint: string; refreshTokenMutation: string; + logoutEndpoint: string; logoutMutation: string; cookieNames?: CookieNames; }; @@ -159,7 +160,7 @@ export function AuthProvider({ const checkToken = useCallback(async () => { const token = await getAccessToken(); updateAuthState(token); - }, [options.authEndpoint, updateAuthState]); + }, [options.refreshTokenEndpoint, updateAuthState]); // Load initial auth state when mounting the application useEffect(() => { @@ -292,7 +293,7 @@ export function AuthProvider({ const refreshAccessToken = async (): Promise => { // Since we are storing the refresh token in a cookie this will be sent // automatically by the browser. - const response = await fetch(options.authEndpoint, { + const response = await fetch(options.refreshTokenEndpoint, { method: "POST", body: options.refreshTokenMutation, headers: { @@ -320,7 +321,7 @@ export function AuthProvider({ const clearTokens = async () => { // Since we are storing the refresh token in a cookie this will be sent // automatically by the browser. - const response = await fetch(options.authEndpoint, { + const response = await fetch(options.logoutEndpoint, { method: "POST", body: options.logoutMutation, headers: {