Redirect to /login on /settings 401 (#295)

Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
ekzyis 2023-06-01 02:47:03 +02:00 committed by GitHub
parent 0c251ca376
commit 36d5478e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,10 +74,22 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re
let error = null; let data = null; let props = {}
if (query) {
({ error, data } = await client.query({
query,
variables: vars
}))
try {
({ error, data } = await client.query({
query,
variables: vars
}))
} catch (err) {
if (err.message === 'you must be logged in') {
const callback = process.env.PUBLIC_URL + req.url
return {
redirect: {
destination: `/login?callbackUrl=${encodeURIComponent(callback)}`
}
}
}
throw err
}
if (error || !data || (notFoundFunc && notFoundFunc(data))) {
return {