-
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.
work in progress add just one file for the duplicated auth logic when…
… we're not using the graphql api for anything else on some pages
- Loading branch information
1 parent
3cd4117
commit 922c6a2
Showing
1 changed file
with
38 additions
and
0 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
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 | ||
} | ||
} |