Skip to content

Commit

Permalink
work in progress add just one file for the duplicated auth logic when…
Browse files Browse the repository at this point in the history
… we're not using the graphql api for anything else on some pages
  • Loading branch information
ehanahamed committed Jan 17, 2025
1 parent 3cd4117 commit 922c6a2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions web/src/lib/fetchAuthData.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export default async function ({ cookies, }) {
let authed = false;
let authedUser;
if (cookies.get("auth")) {
try {
let rawAuthedRes = await fetch(API_URL + "/graphql", {
method: "POST",
headers: {
"Authorization": "Bearer " + cookies.get("auth"),
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query {
authed
authedUser {
id
username
display_name
auth_type
oauth_google_email
}
}`
})
});
let authedRes = await rawAuthedRes.json();
if (authedRes?.data?.authed) {
authed = authedRes.data.authed;
authedUser = authedRes.data?.authedUser
}
} catch (error) {
request.log.error(error);
}
}
return {
authed: authed,
authedUser: authedUser
}
}

0 comments on commit 922c6a2

Please sign in to comment.