Skip to content

Commit

Permalink
fix: refresh token algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
LorexIQ committed Nov 25, 2023
1 parent 5a08213 commit f7b5252
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineNuxtConfig({
localAuth: {
origin: 'https://catman-dev.atrinix.ru/api/v1/',
token: {
lifetime: 5,
lifetime: 60 * 60 * 24,
path: 'access',
queryKey: 'token'
},
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/composables/useLocalAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async function getMe<T extends UseLocalAuthResponse = {}>(): Promise<T> {
if (!token.value) throw new LocalAuthError('getMe > token is null. SignIn first');

try {
await refreshTokenWithCheck();
console.log(await refreshTokenWithCheck())
} catch (e) {}

try {
Expand Down Expand Up @@ -115,6 +115,7 @@ async function refreshToken<T extends UseLocalAuthResponse = {}>(): Promise<T> {

return refreshData;
} catch (e: any) {
await signOut();
throw new LocalAuthError(`refreshToken > [${e.statusCode}] > ${JSON.stringify(e.response._data)}`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export async function fetch<T extends UseLocalAuthResponse>(
meta.value.status = 'timeout';
navigateTo(options.pages.serverIsDown);
}
throw Error(e);
throw e;
}
}

0 comments on commit f7b5252

Please sign in to comment.