Back

[Solved] OAuth2 issues

  • 0
  • Self Hosted
  • Accounts
  • Web
fafa
25 Nov, 2023, 14:26

Heyo, this should work fine, right?

TypeScript
  const handleDiscordLogin = async () => {
    account.createOAuth2Session(
      "discord",
      `${process.env.NEXT_PUBLIC_DOMAIN}/account`,
      `${process.env.NEXT_PUBLIC_DOMAIN}/login?failure=true`
    );
  };
TL;DR
The user had OAuth2 issues, but it was later solved. The solution was to check for the cookie on appwrite.example.com instead of example.com. The user also mentioned using the SDK but wasn't getting any auth cookies or local storage. They were advised to double-check the variables and make sure they were accessible. The user also questioned the use of hardcoded values instead of variables, but it was confirmed that hardcoded values were necessary. The user provided an example code snippet for handling Discord login.
fafa
25 Nov, 2023, 14:29

Getting Missing redirect URL, but I wouldn't know where else to add it.

fafa
25 Nov, 2023, 14:33

And assistant is giving me:

TypeScript
account.create_oauth2_session(
    provider='google',
    success='https://your-website.com/success',
    failure='https://your-website.com/failure'
)

Which is very incorrect <:1lolol:638463120632709144>

fafa
25 Nov, 2023, 14:43

Okay.. so it seems that using variables doesn't work? I have to use hardcoded values. Doesn't make sense in my point of view, but sure?

fafa
25 Nov, 2023, 15:32

OAuth2 issues

fafa
25 Nov, 2023, 15:38

So, after creating a OAuth2 session, what then?

ideclon
26 Nov, 2023, 07:17

It should redirect back to the success var and you should now be logged in?

ideclon
26 Nov, 2023, 07:18

Strange. I would double check the vars are set correctly, and actually accessible here.

fafa
26 Nov, 2023, 08:07

I don't get any auth cookies, local storage, nothing.

Drake
27 Nov, 2023, 16:48

where are you checking this?

fafa
27 Nov, 2023, 16:49

Well, I am using the SDK for this, I thought (just like the login part) it should do this automatically? I check in the browser itself

Drake
27 Nov, 2023, 16:56

so cookies are tied to the domain, not the app. If your appwrite endpoint is at appwrite.example.com and your app is on example.com, the domain would be appwrite.example.com so you'd have to go there to check for the cookie

Drake
27 Nov, 2023, 16:57

local storage isn't used for oauth

fafa
27 Nov, 2023, 16:57

Ah okay, how would I get the cookies on example.com instead?

Drake
27 Nov, 2023, 16:58

if you're not using SSR, it's fine for the cookie to be on appwrite.example.com if your app is on example.com. When your request happens from example.com to appwrite.example.com, the cookie will still be sent

fafa
27 Nov, 2023, 16:58

Thanks!

fafa
28 Nov, 2023, 12:55

[Solved] OAuth2 issues

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