File tree Expand file tree Collapse file tree 5 files changed +14
-74
lines changed
Expand file tree Collapse file tree 5 files changed +14
-74
lines changed Original file line number Diff line number Diff line change 22 * 全てのフィルターを表示するコンポーネント
33 */
44
5- import type {
6- ClassSeries ,
7- ClassType ,
8- Evaluation ,
9- Semester ,
10- } from "@packages/models" ;
5+ import type { ClassSeries , Evaluation , Semester } from "@packages/models" ;
116import { useState } from "react" ;
127import { ClassSeriesFilter } from "./FilterComponents/ClassType.tsx" ;
138import { EvaluationFilter } from "./FilterComponents/Evaluation.tsx" ;
Original file line number Diff line number Diff line change 11import { createAuthClient } from "better-auth/react" ;
2- import { writable } from "svelte/store" ;
32
43export const auth = createAuthClient ( {
54 baseURL : window . location . origin ,
65} ) ;
76
8- export const onAuthChange = writable ( { loggedIn : false } ) ;
9-
107export async function logout ( ) {
118 await auth . signOut ( ) ;
12- onAuthChange . set ( { loggedIn : false } ) ;
139}
1410
1511export async function signInWithGoogle ( callbackURL : string ) {
1612 await auth . signIn . social ( {
1713 provider : "google" ,
1814 callbackURL,
1915 } ) ;
20-
21- onAuthChange . set ( { loggedIn : true } ) ;
2216}
23-
24- ( async ( ) => {
25- const session = await auth . getSession ( ) ;
26- console . log ( "[auth debug] " , session ) ;
27- if ( session . data ) {
28- onAuthChange . set ( { loggedIn : true } ) ;
29- }
30- } ) ( ) ;
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ import { useCurrentUserQuery } from "@/services/user/user";
55export default function Profile ( ) {
66 const user = useCurrentUserQuery ( ) ;
77
8- if ( ! user . data ) {
8+ if ( user . isPending ) {
99 return < div > Loading...</ div > ;
1010 }
1111
12- if ( ! user . data . ok ) {
12+ if ( ! user . data ) {
1313 return (
1414 < div >
1515 Hello anonymous user < GoogleLoginButton callbackURL = "/profile" />
@@ -19,10 +19,10 @@ export default function Profile() {
1919
2020 return (
2121 < div >
22- < div > Hello { user . data . data . name } </ div >
23- { user . data . data . image && (
22+ < div > Hello { user . data . name } </ div >
23+ { user . data . image && (
2424 < img
25- src = { user . data . data . image }
25+ src = { user . data . image }
2626 alt = "profile"
2727 className = "w-20 h-20 rounded-full"
2828 />
Original file line number Diff line number Diff line change 1- import { useNavigate } from "react-router-dom" ;
21import { GoogleLoginButton } from "@/components/auth/GoogleLoginButton" ;
3- import { onAuthChange } from "@/lib/auth-client" ;
4- import { useStoreEffect } from "@/lib/utils/stores" ;
52
63// TODO: style it
4+ // TODO: if user is already logged in, go to /profile
75export default function SignIn ( ) {
8- const navigate = useNavigate ( ) ;
9-
10- useStoreEffect ( onAuthChange , ( auth ) => {
11- console . log ( "[auth debug] " , auth ) ;
12- if ( auth . loggedIn ) {
13- navigate ( "/profile" ) ;
14- }
15- } ) ;
166 return (
177 < div >
188 < GoogleLoginButton callbackURL = "/profile" />
Original file line number Diff line number Diff line change 11import type { UserData } from "@packages/models" ;
2- import type { SelectUser } from "@packages/server/types" ;
3- import { useMutation , useQuery } from "@tanstack/react-query" ;
2+ import { useMutation } from "@tanstack/react-query" ;
43import { env } from "elysia" ;
54import { api } from "@/lib/api" ;
6- import { onAuthChange } from "@/lib/auth-client.ts" ;
5+ import { auth } from "@/lib/auth-client.ts" ;
76import { queryClient } from "@/lib/tanstack/client.ts" ;
87import { keys } from "@/lib/tanstack/keys" ;
98import { sleep } from "@/lib/utils/sleep" ;
109
11- onAuthChange . subscribe ( ( ) => {
12- queryClient . invalidateQueries ( {
13- queryKey : keys . users . currentUser ,
14- } ) ;
15- } ) ;
16-
1710export const useCurrentUserQuery = ( ) => {
18- return useQuery ( {
19- queryKey : keys . users . currentUser ,
20- queryFn : async ( ) : Promise <
21- | {
22- ok : true ;
23- data : SelectUser ;
24- }
25- | {
26- ok : false ;
27- error : Error ;
28- }
29- > => {
30- if ( env . dev ) {
31- await sleep ( 500 ) ;
32- }
33- // TODO: set up mocker
34- const { data, error } = await api . users . me . get ( ) ;
35- if ( error ) {
36- return {
37- ok : false ,
38- error,
39- } ;
40- }
41- return {
42- ok : true ,
43- data,
44- } ;
45- } ,
46- } ) ;
11+ const session = auth . useSession ( ) ;
12+ return {
13+ ...session ,
14+ data : session . data ?. user ,
15+ } ;
4716} ;
4817
4918export const useUpdateUserMutation = ( ) => {
You can’t perform that action at this time.
0 commit comments