Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions server/modules/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ export async function authenticateAndGetGitHubHeaders(event: H3Event<EventHandle
// https://nuxt.com/docs/guide/recipes/sessions-and-authentication
const { secure } = await getUserSession(event);

// check if token is expired and get new one
if (secure && secure.expires_at < new Date(Date.now() - 30 * 1000)) {
// Token is expired or about to expire within 30 seconds
// we could refresh but unlikely dashboard is used for long periods
return buildHeaders('');
}

return buildHeaders(secure?.tokens.access_token || '');
return buildHeaders(secure?.tokens?.access_token || '');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

function buildHeaders(token: string): Headers {
if (!token) {
throw new Error('GitHub token is required');
}

return new Headers({
Accept: "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
Expand Down
Loading