mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +01:00
add a proper login page
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { GetServerSideProps } from 'next'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { GetServerSideProps } from 'next'
|
||||
import Footer from '../../../../components/footer'
|
||||
import Header from '../../../../components/header'
|
||||
import Input from '../../../../components/input'
|
||||
@@ -11,31 +11,26 @@ import { getMilageMax } from '../../../../db/index'
|
||||
import { dateFormatFrontend } from '../../../../helpers/date'
|
||||
import { getBillTotal } from '../../../../helpers/bill'
|
||||
import { getBookingStatus } from '../../../../helpers/booking'
|
||||
import authenticate from '../../../../lib/authenticate'
|
||||
import withSession from '../../../../lib/session'
|
||||
import withSession, { isAdminSession } from '../../../../lib/session'
|
||||
import { getServerSideBooking } from '../../../../lib/getServerSideProps'
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = withSession(
|
||||
async (context) => {
|
||||
const { req, res } = context
|
||||
|
||||
const authenticatedUser = authenticate(req, res)
|
||||
if (!authenticatedUser) {
|
||||
// TODO: not sure if needed
|
||||
req?.session.destroy()
|
||||
const adminUser = isAdminSession(req, res)
|
||||
|
||||
if (!adminUser) {
|
||||
return { props: {} }
|
||||
}
|
||||
|
||||
req.session.set('user', authenticatedUser)
|
||||
await req.session.save()
|
||||
|
||||
const milageMax = await getMilageMax()
|
||||
const result = await getServerSideBooking(context)
|
||||
return {
|
||||
...result,
|
||||
// TODO: have a closer look at this type issue. Seems like a bug
|
||||
// @ts-ignore
|
||||
props: { ...result.props, milageMax },
|
||||
props: { ...result.props, milageMax, user: adminUser },
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -107,7 +102,7 @@ async function saveBill(
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export default function BillPage({
|
||||
export default function BookingBillPage({
|
||||
booking: bookingProp,
|
||||
milageMax,
|
||||
}: {
|
||||
|
||||
Reference in New Issue
Block a user