Skip to content
Back

[SOLVED] Function's payload within OAuth

  • 0
  • Self Hosted
  • Functions
  • Web
AndrewIAm
22 Feb, 2023, 08:59

Ive configured OAuth login and then trying to save user data in DB requested from oauth provider. So I configured run Function on event users . * . sessions . * . create. Is it correct?

Because after it I'm trying to get OAuth provider data (from payload) such as provider name, access_token, userId and so on. Getting current payload from the OAuth: const payload = JSON.parse(process.env.APPWRITE_FUNCTION_EVENT_DATA). But even if session has been deleted on the client side function execution logs say that it's still the same user. Even if user try to login with another OAuth provider. I get current user session using new Account(client).getSession('current') and then accountApi.deleteSession(sessionId). What I did wrong?

Try to simplify: add OAuth provider (2 for now) -> execute function on users . * . sessions . * . create event -> get function payload -> logout user on client side -> login with another provider -> payload in new executed function still the same as before (for another OAuth provider)

TL;DR
User is asking for help regarding accessing the payload within OAuth. They were initially using outdated examples but were redirected to a newer repository. They discovered the correct way to access variables in Appwrite version 1.2.x. They then explain their issue with getting the current user session and payload, even after logging out and logging in with another OAuth provider. They summarize their problem as wanting the payload in a newly executed function to reflect the current OAuth provider, but it remains the same as before. No solution is provided in the thread.
Drake
22 Feb, 2023, 17:16

In Appwrite version 1.2.x, process.env isn't the right way to get variables. Would you please try req.variables.APPWRITE_FUNCTION_EVENT_DATA?

See https://appwrite.io/docs/functions#writingYourOwnFunction for more info

AndrewIAm
22 Feb, 2023, 18:08

You are definitely right <:appwriterocket:823996226894692403> I've found process.env.VAR in the demos for Nodejs, my fault

AndrewIAm
22 Feb, 2023, 18:09

[SOLVED] Function's payload within OAuth

Drake
22 Feb, 2023, 18:12

πŸ‘€ which demos? are they ours?

Drake
22 Feb, 2023, 18:21

oh ya...that repo is archived because it was for our older functions

AndrewIAm
22 Feb, 2023, 18:22

I'm a little dumb so have to check out some examples to understood the logic πŸ˜…

Drake
22 Feb, 2023, 18:23

examples are very helpful...just be very careful about using outdated examples.

These are a little newer: https://github.com/open-runtimes/examples

AndrewIAm
22 Feb, 2023, 18:27

Thanks a lot, very helpful

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