App.jsx
const navigate = useNavigate();
return (
<>
<Routes>
<Route path="/recipe" element={<RecipeDetails/>} />
<Route path="/add" element={<AddRecipe/>} />
<Route path="/" element={<RecipeList/>} />
<Route path="/login" element={<Login/>} />
</Routes>
</>
);
}
export default App;```
**Login.jsx**
async function handleLogin () { account.createOAuth2Session( 'google', 'http://localhost:5173/login', 'http://localhost:5173/fail' ) }
const Login = () => { const [user, setUser] = useState(null) const navigate = useNavigate();
// Check if user is logged in when the component mounts useEffect(() => { const checkSession = async () => { try { const currentUser = await account.get() setUser(currentUser) navigate("/") } catch (error) { console.log("Not logged in") } }
checkSession()
}, [])
return ( <> <div>Login</div> {user ? ( <div> Welcome, {user.name}! </div> ) : ( <button onClick={handleLogin}>LOGIN with GOOGLE</button> )} </> ) }
export default Login
So if you go to /login andclick the button you can login with google and then it takes you back to login. In theory if you logged in correctly the useEffect should redirect you back to / but it doesnt
Attached photo is the console before and after logging in through google. It's the same both times
Recommended threads
- Oauth issue
Hi, can anyone help me in the Oauth issue, Its working fine in dev but its showing Invalid redirect during production. I have check the redirect url and all. St...
- Google/Apple OAuth to show continue to "...
hi everyone, I am building a react-native app with expo and appwrite. I have setup an OAuth flow with Google and Apple following this doc (https://appwrite.io/b...
- Google Auth not working in a React App
Authentication with Google has failed. It redirects back to the signin route in React. Attached screenshots for configuration of Google console and Appwrite Go...