Back

Google Auth not Working

  • 0
  • Users
  • Accounts
  • Databases
  • Web
Ayush_Parui
25 Aug, 2023, 15:57

I'm trying to login a User using google auth after setting up everything in the google cloud console still the user that doesn't exist in the appwrite gets redirect to the dashboard page instead of signup page below is the code.

`import { Client, Account, ID } from "appwrite"; import config from "../conf/config"; const client = new Client(); const account = new Account(client);

client.setEndpoint(config.appwriteURL).setProject(config.appwriteProjectID);

export class authService{

TypeScript
oAuth(){
    try {
        account.createOAuth2Session('google','http://localhost:3000/dashboard', 'http://localhost:3000/signup')
    } catch (error) {
        console.log(error)
        return false
    }    
}

}

const authServices = new authService(); export default authServices;`

`"use client" import authServices from "../../authentication/auth"; import styles from "./styles.module.css"; import { useState } from "react" import { useRouter } from "next/navigation";

const Login = () => {

TypeScript
const googleAuth = (e) => {
    e.preventDefault()
    try {
        authServices.oAuth()
    } catch (error) {
        console.log(error)
    }

}

return (
    <div className={styles.Login}
        <h3>Login Using Google</h3>
        <button onClick={(e) => googleAuth(e)}>Google Login</button>
    </div>
)

}

export default Login;`

TL;DR
Previous session was causing the issue. Trying in a new private window resolved it. Google login is still not working, but GitHub login is successful. Appwrite project URL and project ID are needed to troubleshoot. Google authentication redirects to the dashboard instead of the signup page when using an email address that doesn't exist in Appwrite. There may be an issue with creating the user. Solution: Make sure the correct project and URL are used. Check the code for any errors or missing configurations.
Drake
25 Aug, 2023, 16:56

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Drake
25 Aug, 2023, 16:58

That's weird...if they're redirected to the success url, the user should have been created. Are you sure you're looking at the right project?

Ayush_Parui
25 Aug, 2023, 17:39

Yup I tried a few times but even after signing in with a new email id everytime which doesn't exist in the appwrite it gets logged in where am I making the mistake 😔

Drake
25 Aug, 2023, 18:06

What's the Appwrite URL and project id in your code? Please share a screenshot of the Appwrite console auth page including the URL

Ayush_Parui
26 Aug, 2023, 03:58

APPWRITE_URL = https://cloud.appwrite.io/v1 PROJECT_ID = 64e343b9a0abb92ce533

and the appwrite console auth page means the google 0auth settings screenshot ?

Drake
26 Aug, 2023, 04:38

No the page that shows users in your Appwrite project

Ayush_Parui
26 Aug, 2023, 04:50
Ayush_Parui
26 Aug, 2023, 04:53

I tried github login as well it gets succesfully logged in but I cannot see any user that exist in the appwrite auth with the same email id that was used to sign in to github or google

Ayush_Parui
26 Aug, 2023, 04:55

take a look at this also

Ayush_Parui
26 Aug, 2023, 05:32

okay so the github login is working and I can see the user in the appwrite db but the google is still not working

Ayush_Parui
26 Aug, 2023, 05:42

Okay so I tried in a new private window on my browser and it somehow worked don't know where was the error but it eventually worked thanks for replying @Steven :appwriteparty: :appwriterocket:

Drake
26 Aug, 2023, 05:52

Ah you might have had a previous session that was getting reused

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