From 59f64bc6a0f8131a18165b6304abc2d80f515755 Mon Sep 17 00:00:00 2001 From: Mac mini <> Date: Tue, 31 Mar 2026 15:52:41 +0700 Subject: [PATCH] login with google --- api.ts | 3 ++- src/components/auth/SignInForm.tsx | 15 ++++++--------- src/components/auth/SignUpForm.tsx | 31 +++++++++++++++++++++++++++--- src/service/auth.ts | 8 ++------ 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/api.ts b/api.ts index 017d0cb..14c6028 100644 --- a/api.ts +++ b/api.ts @@ -9,6 +9,7 @@ export const API = { SIGNIN: `${API_URL_ROOT}/auth/signin`, CREATEOTP: `${API_URL_ROOT}/auth/token/create`, VERIFYOTP: `${API_URL_ROOT}/auth/token/verify`, - REFRESH: `${API_URL_ROOT}/auth/refresh` + REFRESH: `${API_URL_ROOT}/auth/refresh`, + GOOGLE_LOGIN: `${API_URL_ROOT}/auth/google/login` } } \ No newline at end of file diff --git a/src/components/auth/SignInForm.tsx b/src/components/auth/SignInForm.tsx index 18f72d4..5b3022b 100644 --- a/src/components/auth/SignInForm.tsx +++ b/src/components/auth/SignInForm.tsx @@ -58,16 +58,13 @@ const [showPassword, setShowPassword] = useState(false); try { setLoading(true); - const res = await apiSignIn(formData); console.log("API Sign In Response:", res); - - const data = await api.get(API.User.CURRENT); - console.log("Current User:", data); - if (res.status === true) { toast.success('Đăng nhập thành công!'); - + + const data = await apiGetCurrentUser(); + console.log("Current User:", data); }else{ toast.error('Email hoặc mật khẩu không đúng.'); } @@ -103,7 +100,7 @@ const [showPassword, setShowPassword] = useState(false);
- - + */}
diff --git a/src/components/auth/SignUpForm.tsx b/src/components/auth/SignUpForm.tsx index f2d6c02..515c070 100644 --- a/src/components/auth/SignUpForm.tsx +++ b/src/components/auth/SignUpForm.tsx @@ -7,6 +7,7 @@ import { apiCreateOTP, apiSignUp, apiVerifyOTP } from "@/service/auth"; import Link from "next/link"; import { useState } from "react"; import { toast } from "sonner"; +import { API } from "../../../api"; export default function SignUpForm() { const [showPassword, setShowPassword] = useState(false); @@ -143,12 +144,36 @@ export default function SignUpForm() { {step === 1 && ( <>
- - + */}
diff --git a/src/service/auth.ts b/src/service/auth.ts index aa71b3e..8eaeb8e 100644 --- a/src/service/auth.ts +++ b/src/service/auth.ts @@ -42,12 +42,8 @@ export const apiSignIn = async (payload: any) => { }; export const apiGetCurrentUser = async () => { - const response = await fetch(API.User.CURRENT,{ - method: "GET", - headers: { "Content-Type": "application/json" }, - credentials: "include", - }); - return response.json(); + const response = await api.get(API.User.CURRENT); + return response?.data; }; export interface ApiResponse {