make isAdminSession usable by api routes

This commit is contained in:
Thomas Ruoff
2020-11-04 00:33:35 +01:00
parent 1dfd1f1f8b
commit 7ee9803adc
5 changed files with 19 additions and 7 deletions

View File

@@ -11,7 +11,10 @@ import { getMilageMax } from '../../../../db/index'
import { dateFormatFrontend } from '../../../../helpers/date'
import { getBillTotal } from '../../../../helpers/bill'
import { getBookingStatus } from '../../../../helpers/booking'
import withSession, { isAdminSession } from '../../../../lib/session'
import withSession, {
isAdminSession,
redirectToLogin,
} from '../../../../lib/session'
import { getServerSideBooking } from '../../../../lib/getServerSideProps'
export const getServerSideProps: GetServerSideProps = withSession(
@@ -21,6 +24,7 @@ export const getServerSideProps: GetServerSideProps = withSession(
const adminUser = isAdminSession(req, res)
if (!adminUser) {
redirectToLogin(req, res)
return { props: {} }
}

View File

@@ -3,7 +3,10 @@ import { GetServerSideProps } from 'next'
import Footer from '../../../../components/footer'
import Header from '../../../../components/header'
import Calendar from '../../../../components/calendar'
import withSession, { isAdminSession } from '../../../../lib/session'
import withSession, {
isAdminSession,
redirectToLogin,
} from '../../../../lib/session'
import { getServerSideBooking } from '../../../../lib/getServerSideProps'
import { BookingDocument } from '../../../../db/booking'
import { getBookingStatus } from '../../../../helpers/booking'
@@ -14,10 +17,10 @@ export const getServerSideProps: GetServerSideProps = withSession(
async (context) => {
const { req, res } = context
console.error('here')
const adminUser = isAdminSession(req, res)
if (!adminUser) {
redirectToLogin(req, res)
return { props: {} }
}