#[SOLVED] missing redirect url Google OAuth web

40 messages · Page 1 of 1 (latest)

grand sandal
#

Hello, I have configure Google OAuth in the google page and Appwrite was enable. And when I have choose account from google, it display error like this.

hasty kindle
#

I'm assuming you're using the web sdk?

From my expirence it's good to add success and failure urls, for example

  account.createOAuth2Session(
        'google',
        window.location.href,
        window.location.href,
    )
#

In this example I'm setting both urls to the current location, but you can of course change it to whatever suits you.

grand sandal
hasty kindle
#

Yes?

grand sandal
#

It's give me back to my login page, but session was create at Appwrite dashboard. How can I check if user was logged in?

Is different with email session?

hasty kindle
#

When being redirect back ( and actually any time ) you shuold add an account.get() function to check if the user is logged in,

Here's an example

// Runns on load.
 let userIsLoggedIn = false;

 try {
    const user         = await account.get();
    userIsLoggedIn = true;
  } catch (e) {
    // That's meeas the user is not logged in.
  }

if(!userIsLoggedIn){
  // In case the user is not logged in show login options
  
}


function login() {
    account.createOAuth2Session('google',
        window.location.href,
        window.location.href,
    )
}
grand sandal
#

emailAddress.value = user.email; <- what is this?

hasty kindle
#

This is just part of my example

#

I've removed it

grand sandal
#

Oh okay, but I have similar code.

#

This my code

    const [isLoading, setIsLoading] = useState<boolean>(true)
    const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false)

    const checkAuth = async () => {
        try {
            await account.get()
            setIsLoggedIn(true)
        } catch (error) {
            console.error(error)
        }
        setIsLoading(false)
    }

    checkAuth()

    return { isLoading, isLoggedIn }
}


export const oauthgoogle = async () => {
    try {
        await account.createOAuth2Session('google',
            window.location.href,
            window.location.href)
    } catch (error) {
        console.error(error)
    }
}```
#

I see code is similar

hasty kindle
#

Cool, That's good

grand sandal
#

But It's not working

hasty kindle
#

What you get here

grand sandal
#

Sould I delete?

hasty kindle
#

I mean what is being print to the console as the error?

grand sandal
#

Nevermind

#

I got this error when check user is logged in or not

hasty kindle
#

I don't know why it dosn't creates the session for you, everything looks intact.

grand sandal
#

Okaayy

#

Maybe I must explore

zenith nebula
# grand sandal I got this error when check user is logged in or not

It could be because of 3rd party cookies. If your app and Appwrite aren't on the same base domain, the Appwrite cookie is considered a 3rd party cookie and the browser may not include it in the request. This is where custom domains come into play: https://appwrite.io/docs/custom-domains

Another problem could be if you're using a framework with server side rendering. If account.get() is called server-side, it won't have the cookie that's on the client

grand sandal
zenith nebula
grand sandal
zenith nebula
grand sandal
#

[SOLVED] missing redirect url Google OAuth web

#

missing redirect url Google OAuth web

#

Hey, why I got this Error, like mismatch url. http / https?

zenith nebula
grand sandal
#

Okay I got it, cause I'm not enable force http redirect from .env

zenith nebula
grand sandal
zenith nebula
#

[SOLVED] missing redirect url Google OAuth web

lucid moss
#

how did you force HTTPS?