Skip to content

Commit

Permalink
fix: Split GraphQL endpoint for refresh vs logout
Browse files Browse the repository at this point in the history
The refresh token endpoint should be different then the logut
  • Loading branch information
mvantellingen committed Nov 29, 2024
1 parent c5e8e42 commit 40138e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-ducks-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/federated-token-react": minor
---

Split GraphQL endpoint for refresh vs logout
9 changes: 5 additions & 4 deletions packages/react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ type AuthContextType = {
const AuthContext = createContext<AuthContextType | undefined>(undefined);

export type AuthProviderProps = {
authEndpoint: string;
refreshTokenEndpoint: string;
refreshTokenMutation: string;
logoutEndpoint: string;
logoutMutation: string;
cookieNames?: CookieNames;
};
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -292,7 +293,7 @@ export function AuthProvider({
const refreshAccessToken = async (): Promise<boolean> => {
// 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: {
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 40138e6

Please sign in to comment.