Back

OAuth get session on SSR

  • 0
  • Accounts
  • Web
HoXsan
26 Aug, 2023, 21:50

Hi guys,

I am a bit new to Appwrite and tried to convert an example app i've built using a tutorial with supabase. The authentication goes trough GitHub, and with Supabase, it returns "code" with the callback. But I do not get "code" when using OAuth with appwrite. I do get authenticated on CSR, and do get informations (have no idea how, as there is no cookies or localstorage tokens), but I can't get anything on SSR.

Do you guys have an example of how this can be accomplished?

Took a look at Meldirons solution, but that is with "anonymous" authentication, which is another flow.

My apps source code: https://github.com/HarunKilic/twitter-clone

TL;DR
The user is having trouble getting a 'key' in the URL when using OAuth with Appwrite. They have tried different approaches but haven't been successful. A workaround suggested is to use '/auth/oauth2/success' as the success path in the SSR app, which will provide a 'secret' in the URL. This 'secret' can be extracted and put in a cookie for future requests. The user also mentions that they are new to Appwrite and are looking for an example of how to accomplish their task. They provide a link to their app's source code on GitHub.
Drake
26 Aug, 2023, 21:55

Ya...we're working on improving the experience with SSR

A workaround right now might be to use /auth/oauth2/success as the success path in your SSR app. When you use this path, there will be a secret in the URL which you can extract and put in a cookie to use for future requests.

Drake
26 Aug, 2023, 21:56
HoXsan
26 Aug, 2023, 22:03

I do not get any success or key in the url.

Tried following:

button action : account.createOAuth2Session('github', ${location.origin}/auth/callback);

in /auth/callback

TypeScript
const requestUrl = new URL(request.url);
const code = requestUrl.searchParams.get("secret");
console.log(requestUrl, code);
// Res - http://localhost:3000/auth/callback | null
Drake
26 Aug, 2023, 22:06

Use the path I suggested

HoXsan
26 Aug, 2023, 22:11

Oh I see. That is a sneaky sneaky one

manazo
18 Sep, 2023, 17:32

Hi. I'm getting a project, key, and secret in the URL. but I'm a bit confused what should I do with these? Can you please show/redirect me to a JS example?

Drake
18 Sep, 2023, 17:35

it would be best to continue in your thread instead of posting here

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more