Skip to content

Commit

Permalink
chore: test doing auth in server layout
Browse files Browse the repository at this point in the history
  • Loading branch information
xynydev committed Apr 20, 2024
1 parent 703c6bb commit ec2b5eb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
export async function load({ locals }) {
export async function load({ locals, cookies }) {
const githubToken = cookies.get("github_oauth_token") ?? null;
const githubUserResponse = await fetch("https://api.github.com/user", {
headers: {
Authorization: `Bearer ${githubToken}`
}
});

return {
githubUser: locals.githubUser
githubUser: githubUserResponse.ok ? await githubUserResponse.json() : null;
};
}

0 comments on commit ec2b5eb

Please sign in to comment.