-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(webapp): Correctly check access token expiration on client side (#…
- Loading branch information
1 parent
64c88d2
commit 5ff7ffc
Showing
4 changed files
with
43 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
import { trace } from '@opentelemetry/api'; | ||
import axios from 'axios'; | ||
import { createHeaders } from './apollo/customFetch'; | ||
import { isBrowser } from 'util/isBrowser'; | ||
import { appConfig } from 'config'; | ||
|
||
export const sendRefreshRequest = async ( | ||
export const sendRefreshRequest = ( | ||
headers: Record<string, string | null> = {} | ||
): Promise<{ accessToken: string; refreshToken: string } | null> => { | ||
try { | ||
const { data } = await axios | ||
.request<any>({ | ||
method: 'post', | ||
baseURL: isBrowser() ? '/' : appConfig.get('API_URL'), | ||
url: '/auth/token/refresh', | ||
withCredentials: isBrowser(), | ||
headers: createHeaders(headers), | ||
}) | ||
.catch((e) => { | ||
throw e; | ||
}); | ||
return data; | ||
} catch (e) { | ||
// TODO: Sentry | ||
console.error(e); | ||
return null; | ||
} | ||
}; | ||
) => | ||
trace | ||
.getTracer('lotta-web') | ||
.startActiveSpan('sendRefreshRequest', async () => { | ||
try { | ||
Sentry.addBreadcrumb({ | ||
category: 'auth', | ||
message: 'trying to refresh token.', | ||
data: { | ||
headers, | ||
isBrowser: isBrowser(), | ||
}, | ||
}); | ||
const { data } = await axios.request<{ | ||
accessToken: string; | ||
refreshToken: string; | ||
} | null>({ | ||
method: 'post', | ||
baseURL: isBrowser() ? '/' : appConfig.get('API_URL'), | ||
url: '/auth/token/refresh', | ||
withCredentials: isBrowser(), | ||
headers: createHeaders(headers), | ||
}); | ||
return data; | ||
} catch (e) { | ||
Sentry.captureException(e); | ||
console.error(e); | ||
return null; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters