#google authentication is not working

212 messages · Page 1 of 1 (latest)

olive sleet
#

Here's the error, I'm facing ```js
{"message":"Not Found","code":404,"type":"general_route_not_found","version":"0.10.26"}


 here's my code ```js
 const handleLogin = () => {
    account.createOAuth2Session("google");
  };

  return (
    <div>
      <button onClick={handleLogin}>Log in with Google</button>
    </div>
  );
}```
drowsy bloom
olive sleet
drowsy bloom
#

What you mean?

olive sleet
#

it's working

#

but why?

drowsy bloom
#

Because without adding any endpoints
Appwrite will use these two as default

$oauthDefaultSuccess = '/auth/oauth2/success';
$oauthDefaultFailure = '/auth/oauth2/failure';

And both of them gonna lead to 404

olive sleet
#

ok

slender smelt
#

I guess login in general is not working. I am also facing this error AppwriteException: Not Found when trying to get loggedin User or trying to create a new user. using email and password

olive sleet
#

one more question how to get verified user data?

drowsy bloom
drowsy bloom
olive sleet
drowsy bloom
slender smelt
olive sleet
#

hey when I do log in with Google it's automatically checking whether is user exists? if the user is not exists then it will add them into auth table

#

i don't want like that if user don't exist then in login it will show error

drowsy bloom
slender smelt
slender smelt
drowsy bloom
drowsy bloom
olive sleet
#

ok

slender smelt
drowsy bloom
# slender smelt

It's a bit hard to grasp react native errors.
Can you share the code in which you're initializing the client?

slender smelt
olive sleet
#

Sorry I mean how to get info of logged In user?😄

slender smelt
slender smelt
#

using there also notFound exception

#

it is print that console.error line

drowsy bloom
olive sleet
#
AppwriteException: User (role: guests) missing scope (account)
drowsy bloom
slender smelt
drowsy bloom
#

The library doesn't work?

slender smelt
#

it is just showing the same thing even with that logs

drowsy bloom
#

Can you try to logged this way

log.debug(error);

So the error won't convert to string?

#

Or even this one

log.debug(error.stack);
slender smelt
drowsy bloom
#

I see in the plugin page that this is the recommend way

log.error("Error", error);

My goal is to get the more details about the error.

slender smelt
#

not giving much info her

drowsy bloom
#

Mmm, That's diffecult to debug,
What I can offer is to check

  • That the project & endoint are correct.
  • The user login details are correct.
slender smelt
olive sleet
#
 const handleLogin = () => {
    account.createOAuth2Session(
      "google",
      window.location.href,
      window.location.href
    );
    setIsLogin(true);
  };

  useEffect(() => {
    if (isLogin) {
      console.log("Login")
      const promise = account.get();
        promise
        .then((res) => {
            console.log(res);
        })
        .catch((err) => {
            console.log(err)
        })
    }
  }, [isLogin]);

return(
<>
   <button onClick={handleLogin}>Log in with Google</button>
</>
)```
#

i don't think my approach is right. please guide me why is it not working? I'm getting same error

olive sleet
#

@drowsy bloom any help?

distant lion
olive sleet
#

is it appwrite cloud or package's bug?

supple mesa
#

I am facing this issue while using the appwrite cloud and flutter for all oauth authentication

#

Happening since yesterday for me

distant lion
supple mesa
#

Yes

distant lion
supple mesa
olive sleet
olive sleet
distant lion
olive sleet
distant lion
supple mesa
#

Also when the bug was not there, whenever login flow was completed, it always showed callback url not configured kind of message. But the login was successful and it got redirected to app

distant lion
supple mesa
#

I see, I missed out on this

olive sleet
#

@distant lion any update?

distant lion
olive sleet
#

now it's different errror

#

@distant lion and @drowsy bloom any guidance?

#

damn this terrible

drowsy bloom
#

What is your client host?

#
const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1')
olive sleet
#
  AppwriteException {
    name: 'AppwriteException',
    code: 401,
    type: 'general_unauthorized_scope',
    response: {
      message: 'User (role: guests) missing scope (account)',
      code: 401,
      type: 'general_unauthorized_scope',
      version: '0.10.28'
    },
    fileName: 'http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=cd345015',
    lineNumber: 550,
    columnNumber: 5,
    message: 'User (role: guests) missing scope (account)'
  }```
#

stuck in this error

#
 account.createOAuth2Session(
      "google",
      window.location.href,
      window.location.href
    );

    const jwt = account.createJWT()

    jwt.then((data) => {
      console.log(data);
    }).catch((err) => {
      console.log(err);
    })
#

this is my code

#

@drowsy bloom any help?

olive sleet
drowsy bloom
#

If you don't set it won't know where to go

#

It works now?

olive sleet
drowsy bloom
#

createOAuth2Session is a 2 step verification
So the jwt part have to happened only after you're redirect back to your website and then you can run the account.createJWT() function.

olive sleet
#

then what to do?

drowsy bloom
#

It will work the same, you code shuold be something like this

  1. Start the OAuth2
 account.createOAuth2Session(
      "google",
      window.location.href,
      window.location.href
    );

Then when the page is load when the user came "back" from Google then run this

// On load

try {
  // First, start the session.
  const uAccount = await account.get(); 
  console.log(uAcconut);

  // Then, you can get the JWT
  const jwt = await account.createJWT();

  console.log(jwt);
} catch (e) {
  console.log(e);
  // Error 401 it's okay. it means the user is not logged in
  // handle errors
}

olive sleet
#

this is terrible

#

docs is misguiding

drowsy bloom
#

What is the value of account?

olive sleet
#

it's given in docs to use it

drowsy bloom
olive sleet
drowsy bloom
#

What error.

olive sleet
#

i thought it should work

drowsy bloom
#

It should

olive sleet
drowsy bloom
#

So to summarize
The user is able to login using Google is being redirect back to your website? successfully?

olive sleet
#

account verified

#

but not able to get user value

drowsy bloom
#

When you run that?

distant lion
olive sleet
#

This is the main concern

distant lion
# olive sleet How to do in localhost?

you can try to google how to enable 3rd party cookies in your browser

otherwise, you'll need to set it up so that your appwrite endpoint is a subdomain of your app. if you don't have a domain, you can edit your hosts file

drowsy bloom
olive sleet
#

i don't know what is the auth mechanism appwrite is using?

olive sleet
#

i earlier tried authentication with supabase and i never faced this kind of difficulty.

#

seriously this error doesn't look like 3rd party cookie User (role: guests) missing scope (account)

distant lion
olive sleet
#

@distant lion I guess i'm getting cookie

distant lion
distant lion
olive sleet
#

also cookie i get from cloud.appwrite

distant lion
distant lion
olive sleet
distant lion
olive sleet
#

also cookie is not storing on cookie section on browser

distant lion
olive sleet
#

then what to do?

#

how to solve google authentication issue?

distant lion
distant lion
olive sleet
#

what if i don't use google auth insteed i use email and password then how to do it?

#

i'm not going to use google auth anymore

distant lion
olive sleet
#
  'error in creating user',
  AppwriteException {
    name: 'AppwriteException',
    code: 400,
    type: 'general_argument_invalid',
    response: {
      message: 'Invalid email: Value must be a valid email address',
      code: 400,
      type: 'general_argument_invalid',
      version: '0.10.29'
    },
    fileName: 'http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=3a11b884',
    lineNumber: 550,
    columnNumber: 5,
    message: 'Invalid email: Value must be a valid email address'
  }```
olive sleet
#

bro seriously what the hell is going on?

#
  account
        .create(uuidv4(), name, email, password)
        .then((res) => {
          account
            .createSession(email, password)
            .then((res1) => {
              console.log(res1)
              navigate("/login");
            })
            .catch((err) => {
              console.log("error in creating session", err);
            });
        })
        .catch((err) => {
          console.log("error in creating user", err);
        });
#

i didn't make any mistake

distant lion
olive sleet
#

i have hosted my app

olive sleet
#

@distant lion and @drowsy bloom thanks for giving ur precious time to my problem

#

I'm able to do successfully authenticate user

light frigate
olive sleet
#

@light frigate

light frigate
#

I'm completely lost in this post, wait one second

olive sleet
#

i know since it's BAAS it will be easier to implement authentication

light frigate
#

Yes, and in fact it's really easy

#

So from what I understand, you are getting error when setting Google Auth, true?

light frigate
#

What do you mean?

light frigate
olive sleet
olive sleet
#

everything is right in google auth setup

#

i have already used this in my other project

light frigate
#

Nope, not configured correctly Auth URLs in the Google cloud pannel

olive sleet
#

it's working fine

#

it's the cookie causing trouble

#

i even tried on appwrite

#

succesfull able to create account

#

so don't tell me it's configured incorrectly

light frigate
#

Not related

#

This post is a bit messy, could you please create a new one with:

  • Your code used related to Auth
  • The error you're getting
  • Google cloud configuration

I'm pretty sure we will manage to solve it

olive sleet
#

i'm not going to distrub u

light frigate
#

We're here to help, so you're not going to disturb me 😅

olive sleet
#

I'm not happy with appwrite

light frigate
#

It's not Appwrite faulty. Seems you're not configuring correctly neither Google cloud console and setting a wrong URL in the function to call oath

olive sleet
#
error AppwriteException: The current user session could not be found.
    at Client.<anonymous> (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=3a11b884:850:17)
    at Generator.next (<anonymous>)
    at fulfilled (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=3a11b884:488:24)
light frigate
#

What's the code used to create the session?

#

What does your Google cloud platform setup has?

daring citrus
#

Thinks that your problem is that cookie is create under localhost domain, wich is not set on appwrite custom domain, so appwrite can't see cookie - can't know that user is logged. Steven already answer this multiple time to you

light frigate
#

Yes, that's mainly the problem, appwrite URL and redirect URL is not being set-up properly, but seems that the end URL is not properly configured too.

Obviously that has nothing to do with appwrite, it's a bad setup

olive sleet
#

I have recently used in my django react project

light frigate
#

It's not the same

#

You can't compare

olive sleet
light frigate
#

Djanjo is a python backend. It doesn't works in the same way as Appwrite. Both have completely different architectures

silver grotto
olive sleet
light frigate
#

Yes, as said, and the function needed to trigger appwrite. If you don't want showing your code publicly, send it to me through PM

light frigate
olive sleet
#

give me a sec

#

I was using react package to authenticate user and django for storing user crediential. This we call client side authentication mechanism

light frigate
#

Nothing to do with appwrite

olive sleet
#

so i'm using vite in that project too

light frigate
#

Please, send your code, if your want send me it through PM

#

And your gcloud configuration

#

In djanjo you're hosting it in localhost, appwrite cloud is hosted under a domain, that's why it doesn't works

olive sleet
#

I'm using react package to authenticatte

light frigate
#

So you're not using appwrite SDk?

olive sleet
#

are u mad?

olive sleet