Skip to content

Commit 40138e6

Browse files
committed
fix: Split GraphQL endpoint for refresh vs logout
The refresh token endpoint should be different then the logut
1 parent c5e8e42 commit 40138e6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

.changeset/sixty-ducks-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@labdigital/federated-token-react": minor
3+
---
4+
5+
Split GraphQL endpoint for refresh vs logout

packages/react/src/provider.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ type AuthContextType = {
5656
const AuthContext = createContext<AuthContextType | undefined>(undefined);
5757

5858
export type AuthProviderProps = {
59-
authEndpoint: string;
59+
refreshTokenEndpoint: string;
6060
refreshTokenMutation: string;
61+
logoutEndpoint: string;
6162
logoutMutation: string;
6263
cookieNames?: CookieNames;
6364
};
@@ -159,7 +160,7 @@ export function AuthProvider({
159160
const checkToken = useCallback(async () => {
160161
const token = await getAccessToken();
161162
updateAuthState(token);
162-
}, [options.authEndpoint, updateAuthState]);
163+
}, [options.refreshTokenEndpoint, updateAuthState]);
163164

164165
// Load initial auth state when mounting the application
165166
useEffect(() => {
@@ -292,7 +293,7 @@ export function AuthProvider({
292293
const refreshAccessToken = async (): Promise<boolean> => {
293294
// Since we are storing the refresh token in a cookie this will be sent
294295
// automatically by the browser.
295-
const response = await fetch(options.authEndpoint, {
296+
const response = await fetch(options.refreshTokenEndpoint, {
296297
method: "POST",
297298
body: options.refreshTokenMutation,
298299
headers: {
@@ -320,7 +321,7 @@ export function AuthProvider({
320321
const clearTokens = async () => {
321322
// Since we are storing the refresh token in a cookie this will be sent
322323
// automatically by the browser.
323-
const response = await fetch(options.authEndpoint, {
324+
const response = await fetch(options.logoutEndpoint, {
324325
method: "POST",
325326
body: options.logoutMutation,
326327
headers: {

0 commit comments

Comments
 (0)