File tree Expand file tree Collapse file tree 2 files changed +30
-14
lines changed
frontend/zicdding-class.com
app/(user)/my/_components Expand file tree Collapse file tree 2 files changed +30
-14
lines changed Original file line number Diff line number Diff line change @@ -7,17 +7,6 @@ import { useRouter } from 'next/navigation';
7
7
import { useEffect } from 'react' ;
8
8
import { useForm } from 'react-hook-form' ;
9
9
10
- function useLoginPageGuard ( nextPage : string ) {
11
- const { isLogged } = useUser ( ) ;
12
- const router = useRouter ( ) ;
13
-
14
- useEffect ( ( ) => {
15
- if ( ! isLogged ) {
16
- router . push ( nextPage ) ;
17
- }
18
- } , [ isLogged , router , nextPage ] ) ;
19
- }
20
-
21
10
export function MyInfo ( { mode } : { mode : 'view' | 'modify' } ) {
22
11
const router = useRouter ( ) ;
23
12
const { user } = useUser ( ) ;
@@ -38,8 +27,6 @@ export function MyInfo({ mode }: { mode: 'view' | 'modify' }) {
38
27
setValue ( 'phoneNumber' , user . phone_num ) ;
39
28
} , [ user , setValue ] ) ;
40
29
41
- useLoginPageGuard ( '/login' ) ;
42
-
43
30
return (
44
31
< div className = "space-y-4 w-[420px] mx-auto my-0" >
45
32
< div className = "w-[200px] flex justify-center ml-auto mr-auto mb-8 flex-col" >
@@ -100,7 +87,12 @@ export function MyInfo({ mode }: { mode: 'view' | 'modify' }) {
100
87
</ Button >
101
88
</ div >
102
89
) : (
103
- < Button className = "w-full rounded-[20px]" onClick = { ( ) => router . push ( '/my/modify' ) } >
90
+ < Button
91
+ className = "w-full rounded-[20px]"
92
+ onClick = { ( ) => {
93
+ router . push ( '/my/modify' ) ;
94
+ } }
95
+ >
104
96
개인정보 수정
105
97
</ Button >
106
98
) }
Original file line number Diff line number Diff line change
1
+ import { NextResponse } from 'next/server' ;
2
+ import type { NextRequest } from 'next/server' ;
3
+ import { apiV1 } from './app/_remotes' ;
4
+
5
+ async function isAuth ( ) {
6
+ try {
7
+ await apiV1 . users . getMe ( ) ;
8
+ return true ;
9
+ } catch {
10
+ return false ;
11
+ }
12
+ }
13
+ export async function middleware ( request : NextRequest ) {
14
+ if ( ! ( await isAuth ( ) ) ) {
15
+ return NextResponse . redirect ( new URL ( '/login' , request . url ) ) ;
16
+ }
17
+
18
+ return NextResponse . next ( ) ;
19
+ }
20
+
21
+ // 미들웨어를 적용할 경로를 지정
22
+ export const config = {
23
+ matcher : [ '/my/:path*' ] ,
24
+ } ;
You can’t perform that action at this time.
0 commit comments