Back

Problem using Google OAuth2

  • 0
  • Web
Drake
29 Sep, 2023, 16:21

What's your code?

TL;DR
User is encountering an error while setting up a development environment with Google OAuth2. They are receiving an error related to node version 10.1.0. They are also seeking advice on achieving role-based routing and passing user data through request headers. They have encountered an error while using the Appwrite SDK and are seeking assistance. The error is related to HTTPS and localhost. The user also wants to know if they can add roles through buttons in React. A solution is provided to change the HTTPS to HTTP and to use a domain instead of localhost for Google Auth.
SreeSen
29 Sep, 2023, 16:51

account.createOAuth2Session('google', 'https://localhost:5173/creator', 'https://localhost:5173') I have used react router for providing the routes.

D5
29 Sep, 2023, 17:07

You can't use localhost as a domain for Google Auth

D5
29 Sep, 2023, 17:07

Google requires having a domain running

D5
29 Sep, 2023, 17:08

Also localhost is not https

D5
29 Sep, 2023, 17:08

Just http

D5
29 Sep, 2023, 17:08

The error you're getting is due to that

SreeSen
29 Sep, 2023, 17:08

But I had used it earlier in one of my projects.

D5
29 Sep, 2023, 17:09

Not sure, but last time I checked it required a domain. But in your case the problem seems to be you're using https instead of http in the URL

SreeSen
29 Sep, 2023, 17:10

Yes I will try that

darShan
29 Sep, 2023, 17:12

I think the problem could be https + localhost

Drake
29 Sep, 2023, 17:39

can you change that https to http?

SreeSen
30 Sep, 2023, 03:33

Yup! It's working now. Thanks!

SreeSen
30 Sep, 2023, 03:34

One more question, is there any way I can add roles, like I have two buttons one for logging in the creator and the other for logging in the editor. What I want to do is whenever either of the buttons is clicked the required role is added to the user.

Drake
30 Sep, 2023, 03:51

Maybe you can use user labels: https://appwrite.io/docs/products/auth/labels

SreeSen
30 Sep, 2023, 04:06

Is there any way I can do this in React? Or should I create a separate node file?

Drake
30 Sep, 2023, 04:07

Maybe create the account using an Appwrite function that can also assign the label

SreeSen
30 Sep, 2023, 04:07

Ok I'll try that

SreeSen
1 Oct, 2023, 05:47

I am trying to create an appwrite function for adding labels to a user. Here is the code: `import { Client, Users } from "node-appwrite";

// This is your Appwrite function // It's executed each time we get a request export default async ({ req, res, log, error }) => { // Why not try the Appwrite SDK? // const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) .setKey(process.env.APPWRITE_API_KEY);

TypeScript
 const users = new Users(client);
 const promise = users.updateLabels(
  req.user_id,
  [ req.role ]

);

promise.then(function (response) { console.log(response); // Success return res.send(response); // Success }, function (error) { console.log(error); // Failure return res.send(error); // Failure });` In the appwrite I am getting this error (as shown in the image), what am I doing wrong? Need help.

Drake
1 Oct, 2023, 05:51

what SDK version is listed in your package.json?

Drake
1 Oct, 2023, 05:52

you're letting hte user add whatever label they want? that doesn't seem safe 🧐

SreeSen
1 Oct, 2023, 06:23

What I am trying to do is achieve role based routing, I want the users to either sign in as creator or editor. For this I have two separate buttons, when the user clicks on it the user will be authenticated and the required role will be added, I was thinking of passing the user id and the role through request headers. Is there any better way to do it?

Drake
1 Oct, 2023, 06:46

At the very least you should validate the input.

Although, honestly, I would do this on the front end the same way you'd have a light theme vs dark theme and letting the user choose between the two

SreeSen
1 Oct, 2023, 06:48

Ok got it

SreeSen
2 Oct, 2023, 05:40

I was following the steps on contributing.md to setup the development environment, after running docker compose build I am getting this error. What I can understand is it is asking for node version 10 something, but when I tried to install this version using nvm it says "npm@10.1.0" is not a valid version or known alias.

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