Skip to content

Commit 90221d0

Browse files
committed
put home page in a try catch block to handle unauthorised
1 parent e203f55 commit 90221d0

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

app/page.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
import { headers } from 'next/headers'
2+
import Layout from 'src/components/Layout'
3+
import Login from 'src/components/Login'
24
import loadSerializableQuery from 'src/relay/loadSerializableQuery'
35
import MainViewQueryNode, { HomeQuery } from '__generated__/HomeQuery.graphql'
46
import HomePage from './Home'
57

68
const Page = async () => {
79
const requestCookie = headers().get('cookie')
8-
const preloadedQuery = await loadSerializableQuery<
9-
typeof MainViewQueryNode,
10-
HomeQuery
11-
>(MainViewQueryNode.params, {}, requestCookie ?? '')
10+
try {
11+
const preloadedQuery = await loadSerializableQuery<
12+
typeof MainViewQueryNode,
13+
HomeQuery
14+
>(MainViewQueryNode.params, {}, requestCookie ?? '')
1215

13-
return (
14-
<div>
15-
<HomePage preloadedQuery={preloadedQuery} cookies={requestCookie ?? ''} />
16-
</div>
17-
)
16+
return (
17+
<div>
18+
<HomePage
19+
preloadedQuery={preloadedQuery}
20+
cookies={requestCookie ?? ''}
21+
/>
22+
</div>
23+
)
24+
} catch (e) {
25+
if ((e as Error)?.message.includes('Unauthorized')) {
26+
return <Layout sidebarContentLeft={<Login />}>Feed goes here.</Layout>
27+
}
28+
}
1829
}
1930

2031
export default Page

0 commit comments

Comments
 (0)