From 15771db1027ffcc8cfbdddb8afa2b6143bb024f3 Mon Sep 17 00:00:00 2001 From: seeleng Date: Wed, 25 Sep 2024 01:12:55 +0800 Subject: [PATCH] fix: set user in store for google oauth --- backend/src/auth/router.py | 2 +- frontend/app/(unauthenticated)/auth/google/page.tsx | 5 ++++- frontend/client/services.gen.ts | 10 +++++++++- frontend/client/types.gen.ts | 12 +++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/backend/src/auth/router.py b/backend/src/auth/router.py index 3a553fec..fc789e86 100644 --- a/backend/src/auth/router.py +++ b/backend/src/auth/router.py @@ -88,7 +88,7 @@ def auth_google( code: str, response: Response, session=Depends(get_session), -): +) -> Token: # 1. Do google oauth stuff token_url = "https://accounts.google.com/o/oauth2/token" data = { diff --git a/frontend/app/(unauthenticated)/auth/google/page.tsx b/frontend/app/(unauthenticated)/auth/google/page.tsx index 67eeef26..af4f4ccd 100644 --- a/frontend/app/(unauthenticated)/auth/google/page.tsx +++ b/frontend/app/(unauthenticated)/auth/google/page.tsx @@ -15,9 +15,11 @@ import { CardTitle, } from "@/components/ui/card"; import { LoadingSpinner } from "@/components/ui/loading-spinner"; +import { useUserStore } from "@/store/user/user-store-provider"; export default function GoogleOAuth() { const router = useRouter(); + const setLoggedIn = useUserStore((state) => state.setLoggedIn); const sentAuthentication = useRef(false); const [isLoading, setIsLoading] = useState(true); const searchParams = useSearchParams(); @@ -31,8 +33,9 @@ export default function GoogleOAuth() { router.push("/login"); return; } - await authGoogleAuthGoogleGet({ query: { code } }); + const response = await authGoogleAuthGoogleGet({ query: { code } }); setIsLoading(false); + setLoggedIn(response.data!.user); router.push("/"); })(); } diff --git a/frontend/client/services.gen.ts b/frontend/client/services.gen.ts index 9096bfb5..8015c7fa 100644 --- a/frontend/client/services.gen.ts +++ b/frontend/client/services.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts import { createClient, createConfig, type Options, urlSearchParamsBodySerializer } from './client'; -import type { SignUpAuthSignupPostData, SignUpAuthSignupPostError, SignUpAuthSignupPostResponse, LogInAuthLoginPostData, LogInAuthLoginPostError, LogInAuthLoginPostResponse, LoginGoogleAuthLoginGoogleGetError, LoginGoogleAuthLoginGoogleGetResponse, AuthGoogleAuthGoogleGetData, AuthGoogleAuthGoogleGetError, AuthGoogleAuthGoogleGetResponse, GetUserAuthSessionGetData, GetUserAuthSessionGetError, GetUserAuthSessionGetResponse, LogoutAuthLogoutGetError, LogoutAuthLogoutGetResponse, RequestPasswordResetAuthPasswordResetPostData, RequestPasswordResetAuthPasswordResetPostError, RequestPasswordResetAuthPasswordResetPostResponse, CompletePasswordResetAuthPasswordResetPutData, CompletePasswordResetAuthPasswordResetPutError, CompletePasswordResetAuthPasswordResetPutResponse, ChangePasswordAuthChangePasswordPutData, ChangePasswordAuthChangePasswordPutError, ChangePasswordAuthChangePasswordPutResponse, GetCategoriesCategoriesGetError, GetCategoriesCategoriesGetResponse, UpdateProfileProfilePutData, UpdateProfileProfilePutError, UpdateProfileProfilePutResponse, GetEventsEventsGetData, GetEventsEventsGetError, GetEventsEventsGetResponse, GetEventEventsIdGetData, GetEventEventsIdGetError, GetEventEventsIdGetResponse, GetEventNotesEventsIdNotesGetData, GetEventNotesEventsIdNotesGetError, GetEventNotesEventsIdNotesGetResponse, ReadEventEventsIdReadPostData, ReadEventEventsIdReadPostError, ReadEventEventsIdReadPostResponse, GetUserQuestionsUserQuestionsGetData, GetUserQuestionsUserQuestionsGetError, GetUserQuestionsUserQuestionsGetResponse, CreateUserQuestionUserQuestionsPostData, CreateUserQuestionUserQuestionsPostError, CreateUserQuestionUserQuestionsPostResponse, GetUserQuestionUserQuestionsIdGetData, GetUserQuestionUserQuestionsIdGetError, GetUserQuestionUserQuestionsIdGetResponse, GetAllNotesNotesGetData, GetAllNotesNotesGetError, GetAllNotesNotesGetResponse, CreateNoteNotesPostData, CreateNoteNotesPostError, CreateNoteNotesPostResponse, UpdateNoteNotesIdPutData, UpdateNoteNotesIdPutError, UpdateNoteNotesIdPutResponse, DeleteNoteNotesIdDeleteData, DeleteNoteNotesIdDeleteError, DeleteNoteNotesIdDeleteResponse, GetPointNotesPointsIdNotesGetData, GetPointNotesPointsIdNotesGetError, GetPointNotesPointsIdNotesGetResponse } from './types.gen'; +import type { SignUpAuthSignupPostData, SignUpAuthSignupPostError, SignUpAuthSignupPostResponse, LogInAuthLoginPostData, LogInAuthLoginPostError, LogInAuthLoginPostResponse, LoginGoogleAuthLoginGoogleGetError, LoginGoogleAuthLoginGoogleGetResponse, AuthGoogleAuthGoogleGetData, AuthGoogleAuthGoogleGetError, AuthGoogleAuthGoogleGetResponse, GetUserAuthSessionGetData, GetUserAuthSessionGetError, GetUserAuthSessionGetResponse, LogoutAuthLogoutGetError, LogoutAuthLogoutGetResponse, RequestPasswordResetAuthPasswordResetPostData, RequestPasswordResetAuthPasswordResetPostError, RequestPasswordResetAuthPasswordResetPostResponse, CompletePasswordResetAuthPasswordResetPutData, CompletePasswordResetAuthPasswordResetPutError, CompletePasswordResetAuthPasswordResetPutResponse, ChangePasswordAuthChangePasswordPutData, ChangePasswordAuthChangePasswordPutError, ChangePasswordAuthChangePasswordPutResponse, GetCategoriesCategoriesGetError, GetCategoriesCategoriesGetResponse, UpdateProfileProfilePutData, UpdateProfileProfilePutError, UpdateProfileProfilePutResponse, GetEventsEventsGetData, GetEventsEventsGetError, GetEventsEventsGetResponse, GetEventEventsIdGetData, GetEventEventsIdGetError, GetEventEventsIdGetResponse, GetEventNotesEventsIdNotesGetData, GetEventNotesEventsIdNotesGetError, GetEventNotesEventsIdNotesGetResponse, ReadEventEventsIdReadPostData, ReadEventEventsIdReadPostError, ReadEventEventsIdReadPostResponse, SearchWhateverEventsSearchGetData, SearchWhateverEventsSearchGetError, SearchWhateverEventsSearchGetResponse, GetUserQuestionsUserQuestionsGetData, GetUserQuestionsUserQuestionsGetError, GetUserQuestionsUserQuestionsGetResponse, CreateUserQuestionUserQuestionsPostData, CreateUserQuestionUserQuestionsPostError, CreateUserQuestionUserQuestionsPostResponse, GetUserQuestionUserQuestionsIdGetData, GetUserQuestionUserQuestionsIdGetError, GetUserQuestionUserQuestionsIdGetResponse, GetAllNotesNotesGetData, GetAllNotesNotesGetError, GetAllNotesNotesGetResponse, CreateNoteNotesPostData, CreateNoteNotesPostError, CreateNoteNotesPostResponse, UpdateNoteNotesIdPutData, UpdateNoteNotesIdPutError, UpdateNoteNotesIdPutResponse, DeleteNoteNotesIdDeleteData, DeleteNoteNotesIdDeleteError, DeleteNoteNotesIdDeleteResponse, GetPointNotesPointsIdNotesGetData, GetPointNotesPointsIdNotesGetError, GetPointNotesPointsIdNotesGetResponse } from './types.gen'; export const client = createClient(createConfig()); @@ -130,6 +130,14 @@ export const readEventEventsIdReadPost = ( url: '/events/:id/read' }); }; +/** + * Search Whatever + */ +export const searchWhateverEventsSearchGet = (options: Options) => { return (options?.client ?? client).get({ + ...options, + url: '/events/search' +}); }; + /** * Get User Questions */ diff --git a/frontend/client/types.gen.ts b/frontend/client/types.gen.ts index 040e3131..b2657989 100644 --- a/frontend/client/types.gen.ts +++ b/frontend/client/types.gen.ts @@ -188,7 +188,7 @@ export type AuthGoogleAuthGoogleGetData = { }; }; -export type AuthGoogleAuthGoogleGetResponse = (unknown); +export type AuthGoogleAuthGoogleGetResponse = (Token); export type AuthGoogleAuthGoogleGetError = (HTTPValidationError); @@ -285,6 +285,16 @@ export type ReadEventEventsIdReadPostResponse = (unknown); export type ReadEventEventsIdReadPostError = (HTTPValidationError); +export type SearchWhateverEventsSearchGetData = { + query: { + query: string; + }; +}; + +export type SearchWhateverEventsSearchGetResponse = (unknown); + +export type SearchWhateverEventsSearchGetError = (HTTPValidationError); + export type GetUserQuestionsUserQuestionsGetData = unknown; export type GetUserQuestionsUserQuestionsGetResponse = (Array);