#[SOLVED] missing redirect url Google OAuth web
40 messages · Page 1 of 1 (latest)
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.
Yes, I'm use web SDK
This code is work, but I have other question now
Yes?
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?
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,
)
}
emailAddress.value = user.email; <- what is this?
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
Cool, That's good
But It's not working
What you get here
I just copy from another login with mail session
Sould I delete?
I mean what is being print to the console as the error?
I don't know why it dosn't creates the session for you, everything looks intact.
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
How if I in development mode, whic is use localhost as domain or ip 127.0.0.1 ? It's not problem?
that will probably be a problem because localhost or 127.0.0.1 do not have the same base domain as your appwrite server
How best practice if we want to develop in localhost?
Update your hosts file to point some domain to localhost
[SOLVED] missing redirect url Google OAuth web
missing redirect url Google OAuth web
Hey, why I got this Error, like mismatch url. http / https?
Is appwrite behind a reverse proxy?
I activate the proxy in cloudflare
Okay I got it, cause I'm not enable force http redirect from .env
Did that fix it?
Yeah, I enabled the force redirect https
[SOLVED] missing redirect url Google OAuth web
how did you force HTTPS?