Skip to content

Commit

Permalink
debug token handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Klesse committed Sep 4, 2024
1 parent 2818df4 commit 1b69961
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions src/runtime/composables/gql-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,16 @@ export async function gqlMutation<T = any>(method: string, options: IGraphQLOpti
console.debug('gqlMutation::documentNode ', documentNode);
}

let accessToken;
if (method !== 'refreshToken' || !config.disableTokenCheck) {
const tokens = await callWithNuxt(_nuxtApp, checkTokenAndRenew);
console.debug('gqlMutation::tokens ', tokens);
if (tokens) {
accessToken = tokens.token;
}
await callWithNuxt(_nuxtApp, checkTokenAndRenew);
}

const requestHeaders = {
authorization: `Bearer ${method === 'refreshToken' ? refreshTokenState.value : accessToken}`,
authorization: `Bearer ${method === 'refreshToken' ? refreshTokenState.value : accessTokenState.value}`,
};

console.debug('make request with following token', requestHeaders.authorization);

let data;
let error;
try {
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/composables/use-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export function useAuth() {
// Get and set new tokens
const { data } = await gqlMutation('refreshToken', { disableTokenCheck: true, fields: ['token', 'refreshToken'] });

if (data.value?.refreshToken) {
setTokens(data.value.refreshToken.token, data.value.refreshToken.refreshToken);
if (data?.refreshToken) {
setTokens(data.refreshToken.token, data.refreshToken.refreshToken);
} else {
return null;
}

const result = {
refreshToken: data.value.refreshToken.refreshToken,
token: data.value.refreshToken.token,
refreshToken: data.refreshToken.refreshToken,
token: data.refreshToken.token,
};

// Allow further calls again and transfer the result to waiting processes
Expand Down

0 comments on commit 1b69961

Please sign in to comment.