Skip to content

Commit e8ce64a

Browse files
committed
fix: no user retruning 403
1 parent 710c43b commit e8ce64a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

ui/pages/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ interface User {
1717
exp: number;
1818
}
1919

20-
const Home: NextPage = ({ fallbackData }) => {
21-
const { data } = useSwr<User>(
20+
const Home: NextPage<{ fallbackData: User }> = ({ fallbackData }) => {
21+
const { data } = useSwr<User | null>(
2222
`${process.env.NEXT_PUBLIC_SERVER_ENDPOINT}/api/me`,
2323
fetcher,
2424
{ fallbackData }

ui/utils/fetcher.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import axios from "axios";
22

3-
const fetcher = <T>(url: string, headers = {}): Promise<T> =>
4-
axios
5-
.get<T>(url, {
3+
const fetcher = async <T>(url: string, headers = {}): Promise<T | null> => {
4+
try {
5+
const { data } = await axios.get<T>(url, {
66
headers,
77
withCredentials: true,
8-
})
9-
.then((res) => res.data);
8+
});
9+
10+
return data;
11+
} catch (e) {
12+
return null;
13+
}
14+
};
1015

1116
export default fetcher;

0 commit comments

Comments
 (0)