mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-18 21:44:07 +01:00
Add google login to signup / Increase profile dropdown z
This commit is contained in:
parent
c71020f947
commit
ae2b55bf0e
@ -7,6 +7,8 @@ import { loadFull } from "tsparticles";
|
|||||||
import refreshAccessToken from "./refreshAcesstoken";
|
import refreshAccessToken from "./refreshAcesstoken";
|
||||||
import axiosapi from "../../api/AuthenticationApi";
|
import axiosapi from "../../api/AuthenticationApi";
|
||||||
import { useAuth } from "../../hooks/authentication/IsAuthenticated";
|
import { useAuth } from "../../hooks/authentication/IsAuthenticated";
|
||||||
|
import { FcGoogle } from "react-icons/fc";
|
||||||
|
|
||||||
|
|
||||||
function LoginPage() {
|
function LoginPage() {
|
||||||
const Navigate = useNavigate();
|
const Navigate = useNavigate();
|
||||||
@ -208,7 +210,7 @@ function LoginPage() {
|
|||||||
className="btn btn-outline btn-secondary w-full "
|
className="btn btn-outline btn-secondary w-full "
|
||||||
onClick={() => googleLoginImplicit()}
|
onClick={() => googleLoginImplicit()}
|
||||||
>
|
>
|
||||||
Login with Google
|
<FcGoogle className="rounded-full bg-white"/>Login with Google
|
||||||
</button>
|
</button>
|
||||||
{/* Forgot Password Link */}
|
{/* Forgot Password Link */}
|
||||||
<div className="justify-left">
|
<div className="justify-left">
|
||||||
|
|||||||
@ -4,6 +4,9 @@ import axiosapi from "../../api/AuthenticationApi";
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import Particles from "react-tsparticles";
|
import Particles from "react-tsparticles";
|
||||||
import { loadFull } from "tsparticles";
|
import { loadFull } from "tsparticles";
|
||||||
|
import { FcGoogle } from "react-icons/fc";
|
||||||
|
import { useGoogleLogin } from "@react-oauth/google";
|
||||||
|
|
||||||
|
|
||||||
function Copyright(props) {
|
function Copyright(props) {
|
||||||
return (
|
return (
|
||||||
@ -64,6 +67,28 @@ export default function SignUp() {
|
|||||||
console.log(container);
|
console.log(container);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const googleLoginImplicit = useGoogleLogin({
|
||||||
|
flow: "auth-code",
|
||||||
|
redirect_uri: "postmessage",
|
||||||
|
onSuccess: async (response) => {
|
||||||
|
try {
|
||||||
|
const loginResponse = await axiosapi.googleLogin(response.code);
|
||||||
|
if (loginResponse && loginResponse.data) {
|
||||||
|
const { access_token, refresh_token } = loginResponse.data;
|
||||||
|
|
||||||
|
localStorage.setItem("access_token", access_token);
|
||||||
|
localStorage.setItem("refresh_token", refresh_token);
|
||||||
|
setIsAuthenticated(true);
|
||||||
|
Navigate("/");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error with the POST request:", error);
|
||||||
|
setIsAuthenticated(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (errorResponse) => console.log(errorResponse),
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-theme="night"
|
data-theme="night"
|
||||||
@ -197,6 +222,14 @@ export default function SignUp() {
|
|||||||
<button className="btn btn-success w-full " onClick={handleSubmit}>
|
<button className="btn btn-success w-full " onClick={handleSubmit}>
|
||||||
Signup
|
Signup
|
||||||
</button>
|
</button>
|
||||||
|
<div className="divider">OR</div>
|
||||||
|
{/* Login with Google Button */}
|
||||||
|
<button
|
||||||
|
className="btn btn-outline btn-secondary w-full "
|
||||||
|
onClick={() => googleLoginImplicit()}
|
||||||
|
>
|
||||||
|
<FcGoogle className="rounded-full bg-white"/>Login with Google
|
||||||
|
</button>
|
||||||
{/* Already have an account? */}
|
{/* Already have an account? */}
|
||||||
<div className="text-blue-500 flex justify-center text-sm">
|
<div className="text-blue-500 flex justify-center text-sm">
|
||||||
<a href="login">
|
<a href="login">
|
||||||
|
|||||||
@ -39,7 +39,7 @@ function NavBar() {
|
|||||||
</label>
|
</label>
|
||||||
<ul
|
<ul
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
className="mt-3 z-[1] p-2 shadow menu menu-sm dropdown-content bg-base-100 rounded-box w-52">
|
className="mt-3 z-[10] p-2 shadow menu menu-sm dropdown-content bg-base-100 rounded-box w-52">
|
||||||
<li>
|
<li>
|
||||||
<a href={settings.Profile} className="justify-between">
|
<a href={settings.Profile} className="justify-between">
|
||||||
Profile
|
Profile
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user