Skip to content

Commit

Permalink
Reset session if fetching private page fails
Browse files Browse the repository at this point in the history
  • Loading branch information
backjonas committed Sep 6, 2023
1 parent 93f1012 commit 3b6bee2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pages/medlem/[privatePage].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ const PrivatePage: NextPage<PrivatePageProps> = ({
session,
...props
}: PrivatePageProps) => (
<Page {...props} isPrivate={true} unauthorized={!session || !props.page} />
<Page {...props} isPrivate={true} unauthorized={session === null} />
)

export const getServerSideProps: GetServerSideProps<{
session: Session | null
}> = async (context) => {
const query = context.query.privatePage
const slug = query instanceof Array ? query[0] : query
const session = await getSession(context)
const page = session?.user?.token
? await fetchPrivatePage(session?.user.token, slug)
: null
let session = await getSession(context)
const page = await fetchPrivatePage(session?.user.token, slug)
// Reset the session if page fetch failed as it's most likely caused by an invalid session token
if (page === null) {
session = null
}
const { logos, navbarLinks } = await getLayoutProps()
return {
props: {
Expand Down

0 comments on commit 3b6bee2

Please sign in to comment.