File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
typing-app/src/components/pages Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 1
1
"use client" ;
2
2
import { ResultScore } from "@/types/RegisterScore" ;
3
3
import { VStack } from "@chakra-ui/react" ;
4
- import React , { useState } from "react" ;
4
+ import React , { useState , useEffect } from "react" ;
5
5
import GamePre from "../templates/GamePre" ;
6
6
import GameResult from "../templates/GameResult" ;
7
7
import GameTyping from "../templates/GameTyping" ;
8
+ import { useRouter } from "next/navigation" ;
9
+ import { showWarningToast } from "@/utils/toast" ;
10
+ import { User } from "@/types/user" ;
11
+ import { getCurrentUser } from "@/app/actions" ;
8
12
9
13
export interface GamePreProps {
10
14
nextPage : ( ) => void ;
@@ -22,6 +26,22 @@ interface GamePageProps {
22
26
}
23
27
24
28
const GamePage : React . FC < GamePageProps > = ( { subjectText } ) => {
29
+ //ログインしていなければ、トップページにリダイレクト
30
+ const router = useRouter ( ) ;
31
+ const isUserLoggedIn = async ( ) => {
32
+ const user : User | undefined = await getCurrentUser ( ) ;
33
+ return user ;
34
+ }
35
+
36
+ useEffect ( ( ) => {
37
+ isUserLoggedIn ( ) . then ( ( user ) => {
38
+ if ( ! user ) {
39
+ showWarningToast ( "ログインしてください" ) ;
40
+ router . push ( "/" ) ;
41
+ }
42
+ } ) ;
43
+ } , [ ] ) ;
44
+
25
45
const ScreenIndex = {
26
46
IDX_PRE : 0 ,
27
47
IDX_TYPING : 1 ,
You can’t perform that action at this time.
0 commit comments