Skip to content

fix: validate oauth token on load#194

Merged
olivermrose merged 1 commit into
mainfrom
fix/validate-oauth
May 23, 2026
Merged

fix: validate oauth token on load#194
olivermrose merged 1 commit into
mainfrom
fix/validate-oauth

Conversation

@olivermrose
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings May 23, 2026 22:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds client-side validation of a previously stored Twitch OAuth token during the root layout load, clearing the stored user when the token is expired.

Changes:

  • Updates the root +layout.ts load signature to receive fetch.
  • Calls Twitch’s oauth2/validate endpoint on load when a stored user token exists.
  • Clears the stored user when validation returns 401 Unauthorized.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/routes/+layout.ts
Comment on lines +19 to +28
if (storage.state.user) {
const response = await fetch("https://id.twitch.tv/oauth2/validate", {
headers: { Authorization: `OAuth ${storage.state.user.token}` },
});

if (response.status === 401) {
log.info("Stored token expired, clearing user");
storage.state.user = null;
}
}
Comment thread src/routes/+layout.ts
Comment on lines +14 to +21
export async function load({ url, fetch }) {
if (url.searchParams.has("detached")) {
return { detached: true };
}

if (storage.state.user) {
const response = await fetch("https://id.twitch.tv/oauth2/validate", {
headers: { Authorization: `OAuth ${storage.state.user.token}` },
Comment thread src/routes/+layout.ts
Comment on lines +24 to +27
if (response.status === 401) {
log.info("Stored token expired, clearing user");
storage.state.user = null;
}
@olivermrose olivermrose merged commit 81b70da into main May 23, 2026
2 of 3 checks passed
@olivermrose olivermrose deleted the fix/validate-oauth branch May 23, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants