mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
make isAdminSession usable by api routes
This commit is contained in:
@@ -12,17 +12,20 @@ export default function withSession(handler: Handler) {
|
||||
// the next line allows to use the session in non-https environements like
|
||||
// Next.js dev mode (http://localhost:3000)
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
path: '/admin',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const isAdminSession = function (req: any, res: any) {
|
||||
export function isAdminSession(req: any, res: any) {
|
||||
const user = req?.session.get('user')
|
||||
if (user && user.role === 'admin') {
|
||||
return user
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export function redirectToLogin(req: any, res: any) {
|
||||
const redirectTargetUrl = `${getBaseURL()}/admin/login?redirect=${encodeURIComponent(
|
||||
req.url
|
||||
)}`
|
||||
@@ -31,6 +34,4 @@ export const isAdminSession = function (req: any, res: any) {
|
||||
Location: redirectTargetUrl,
|
||||
})
|
||||
res.end()
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user