File tree Expand file tree Collapse file tree 6 files changed +27
-18
lines changed
app/(with-tracker)/(login) Expand file tree Collapse file tree 6 files changed +27
-18
lines changed Original file line number Diff line number Diff line change @@ -75,10 +75,9 @@ export const instance = async <I, R>(
7575 return ( data . body as unknown as SuccessType < R > ) . data ;
7676 } catch ( err : unknown ) {
7777 const context = err as Response ;
78- if ( location && ! context . ok && context . status === 403 ) {
78+ if ( location && ! context . ok && context . status === 401 ) {
7979 window . location . replace ( '/' ) ;
8080 }
81- //context.status === 401 ||
8281 setContext ( 'Request' , {
8382 path : context . url ,
8483 status : context . status ,
Original file line number Diff line number Diff line change 33import { useRouter } from 'next/navigation' ;
44import { useForm } from 'react-hook-form' ;
55import Image from 'next/image' ;
6- import { useMutation , useQueryClient } from '@tanstack/react-query' ;
6+ import { useMutation } from '@tanstack/react-query' ;
77import { Input , Button } from '@/components' ;
88import { LoginVo } from '@/types' ;
99import { login , sampleLogin } from '@/apis' ;
@@ -14,7 +14,6 @@ const responsiveStyle =
1414
1515export const Content = ( ) => {
1616 const { replace } = useRouter ( ) ;
17- const client = useQueryClient ( ) ;
1817
1918 const {
2019 register,
@@ -23,7 +22,6 @@ export const Content = () => {
2322 } = useForm < LoginVo > ( { mode : 'all' } ) ;
2423
2524 const onSuccess = ( ) => {
26- client . clear ( ) ;
2725 trackUserEvent ( MessageEnum . LOGIN ) ;
2826 replace ( '/main?asc=false&sort=' ) ;
2927 } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ import { NameType } from '@/components';
99import { useResponsive } from '@/hooks' ;
1010import { logout , me } from '@/apis' ;
1111import { trackUserEvent , MessageEnum } from '@/utils/trackUtil' ;
12+ import { revalidate } from '@/utils/revalidateUtil' ;
13+
1214import { defaultStyle , Section , textStyle } from './Section' ;
1315
1416const PARAMS = {
@@ -37,13 +39,19 @@ export const Header = () => {
3739
3840 const { mutate : out } = useMutation ( {
3941 mutationFn : logout ,
40- onMutate : ( ) => router . replace ( '/' ) ,
41- onSuccess : ( ) => client . removeQueries ( ) ,
42+ onSuccess : async ( ) => {
43+ await revalidate ( ) ;
44+ client . clear ( ) ;
45+ router . replace ( '/' ) ;
46+ } ,
4247 } ) ;
4348
4449 const { data : profiles } = useQuery ( {
4550 queryKey : [ PATHS . ME ] ,
4651 queryFn : me ,
52+ enabled : ! ! client . getQueryData ( [ PATHS . ME ] ) ,
53+ // 로그아웃 후 리렌더링되어 다시 fetch되는 경우 해결
54+ // 어차피 prefetch를 통해 데이터를 불러온 상태에서 렌더하기 때문에, 캐시 여부만 판단하면 됨
4755 } ) ;
4856
4957 useEffect ( ( ) => {
Original file line number Diff line number Diff line change 11'use client' ;
22
3- import { useQueryClient } from '@tanstack/react-query' ;
43import { useState } from 'react' ;
5- import { UserNameNotFoundError } from '@/errors' ;
64import { trackUserEvent , MessageEnum } from '@/utils/trackUtil' ;
75import { parseNumber } from '@/utils/numberUtil' ;
86import { COLORS , env , PATHS } from '@/constants' ;
97import { PostType , UserDto } from '@/types' ;
108import { Icon } from '@/components' ;
9+ import { getQueryClient } from '@/utils/queryUtil' ;
1110import { Graph } from './Graph' ;
1211
1312export const Section = ( p : PostType ) => {
1413 const [ open , setOpen ] = useState ( false ) ;
15- const client = useQueryClient ( ) ;
1614
17- const { username } = client . getQueryData ( [ PATHS . ME ] ) as UserDto ;
18- const URL = env . VELOG_URL ;
15+ const username = (
16+ getQueryClient ( ) . getQueryData ( [ PATHS . ME ] ) as Partial < UserDto >
17+ ) ?. username ;
1918
20- if ( ! username ) {
21- throw new UserNameNotFoundError ( ) ;
22- }
23-
24- const url = `${ URL } /@${ username } /${ p . slug } ` ;
19+ const url = `${ env . VELOG_URL } /@${ username } /${ p . slug } ` ;
2520
2621 return (
2722 < section className = "flex flex-col w-full h-fit relative" >
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { toast } from 'react-toastify';
33
44let localQueryClient : QueryClient | undefined ;
55const STALE_TIME = 1000 * 60 * 3 ;
6- const GC_TIME = 1000 ;
6+ const GC_TIME = 1000 * 60 * 20 ;
77
88const createQueryClient = ( ) =>
99 new QueryClient ( {
Original file line number Diff line number Diff line change 1+ 'use server' ;
2+
3+ import { revalidatePath } from 'next/cache' ;
4+ import { redirect } from 'next/navigation' ;
5+
6+ export async function revalidate ( ) {
7+ revalidatePath ( '/' , 'layout' ) ;
8+ redirect ( '/' ) ;
9+ }
You can’t perform that action at this time.
0 commit comments