Skip to content

Commit 0ea6c77

Browse files
committed
feat: path에서 userId 제거하여 browse 단순화
1 parent d70fc37 commit 0ea6c77

File tree

1 file changed

+15
-35
lines changed

1 file changed

+15
-35
lines changed

src/pages/browse/[userId].tsx renamed to src/pages/browse/index.tsx

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type {
2-
GetStaticPaths,
3-
GetStaticProps,
4-
InferGetStaticPropsType,
2+
GetServerSideProps,
3+
InferGetServerSidePropsType
54
} from 'next';
65
import { useState, useEffect, useCallback } from 'react';
76
import { api } from '~/utils/api';
@@ -41,8 +40,8 @@ const FileCard = styled('div')({
4140
});
4241

4342
const BrowsePage = ({
44-
userId,
45-
}: InferGetStaticPropsType<typeof getStaticProps>) => {
43+
login,
44+
}: InferGetServerSidePropsType<typeof getServerSideProps>) => {
4645
const [token, setToken] = useState<string | null>(null);
4746
const utils = api.useContext();
4847

@@ -76,23 +75,19 @@ const BrowsePage = ({
7675
// Check for stored token on mount
7776
useEffect(() => {
7877
const storedToken = localStorage.getItem('authToken');
79-
if (storedToken) {
80-
if (!currentUser || currentUser.name === userId) {
81-
setToken(storedToken);
82-
} else {
83-
localStorage.removeItem('authToken');
84-
}
85-
} else if (!signInMutation.isPending && !signInMutation.error) {
78+
if (storedToken && !login) {
79+
setToken(storedToken);
80+
} else if (!signInMutation.isSuccess && !signInMutation.isPending && !signInMutation.error) {
8681
void handleLogin();
8782
}
88-
}, [currentUser, userId, handleLogin, signInMutation]);
83+
}, [currentUser, login, handleLogin, signInMutation]);
8984

9085
if (signInMutation.error) {
9186
return (
9287
<Container>
93-
<Title>Login Failed</Title>
88+
<Title>Access Denied</Title>
9489
<div className="text-center text-red-500">
95-
Please refresh to try again.
90+
Login failed. Please refresh to try again.
9691
</div>
9792
</Container>
9893
);
@@ -102,16 +97,8 @@ const BrowsePage = ({
10297
return (
10398
<Container>
10499
<Title>Waiting for authentication...</Title>
105-
</Container>
106-
);
107-
}
108-
109-
if (currentUser.name !== userId) {
110-
return (
111-
<Container>
112-
<Title>Access Denied</Title>
113100
<div className="text-center text-red-500">
114-
You cannot access files that do not belong to you.
101+
Please refresh this page if nothing happens.
115102
</div>
116103
</Container>
117104
);
@@ -146,21 +133,14 @@ const BrowsePage = ({
146133
);
147134
};
148135

149-
export const getStaticProps = (async ({ params }) => {
150-
const userId = params!.userId as string;
136+
export const getServerSideProps = (async ({ query }) => {
137+
const login = query?.login ?? null;
151138

152139
return {
153140
props: {
154-
userId,
141+
login,
155142
},
156143
};
157-
}) satisfies GetStaticProps;
158-
159-
export const getStaticPaths = (async () => {
160-
return {
161-
paths: [],
162-
fallback: 'blocking',
163-
};
164-
}) satisfies GetStaticPaths;
144+
}) satisfies GetServerSideProps;
165145

166146
export default BrowsePage;

0 commit comments

Comments
 (0)