brandonk3nt
brandonk3nt2w ago

Google OAuth2 flow with Deno Fresh

Asking for a little assistance with my Google auth flow- specifically for nuances with redirecting and creating/accessing cookies (I use a "token" cookie for auth). Here's my current flow, please advise where something looks "off": 1. User clicks Google OAuth link and does the OAuth "dance" with Google in a popup. 2. Google OAuth redirects to my redirect_url 3. At my redirect URL, I create a token and set it as a cookie, then redirect to my authenticated home route *with a 302 response and a "location" header. (Should I be using Response.redirect("/") here instead of a 302? The problem is that at "/" when I try to read the cookie I set in step #3, server-side logs show that the cookie doesn't exist even though I just set it, but I can see it plain as day in the chrome dev tools. Any suggestions or walkthru's for Google Oauth flow? Thanks!
2 Replies
MaDsEn
MaDsEn2w ago
It could be a timing issue making the redirect happen before the cookie is set. Are you using a library for oauth2. At your "/" have you tried adding console logs showing console.log('All cookies:', req.cookies); console.log('Auth token:',... I myself are using https://jsr.io/@maks11060/oauth2, and it works great, and tested it with Google, discord, github, Facebook, Instagram and it works great
iuioiua
iuioiua2w ago
JSR
@deno/kv-oauth - JSR
@deno/kv-oauth on JSR: High-level OAuth 2.0 powered by Deno KV.

Did you find this page helpful?