mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
move login and add logout
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Bill } from '../../../../../db/bill'
|
||||
import { createBill, patchBill } from '../../../../../db/index'
|
||||
import withSession, { isAdminSession } from '../../../../../lib/session'
|
||||
import { Bill } from '../../../../db/bill'
|
||||
import { createBill, patchBill } from '../../../../db/index'
|
||||
import withSession, { isAdminSession } from '../../../../lib/session'
|
||||
|
||||
export default withSession(async function billHandler(req, res): Promise<void> {
|
||||
if (!isAdminSession(req)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { authenticateAdmin } from '../../../lib/authenticate'
|
||||
import withSession from '../../../lib/session'
|
||||
import { authenticateAdmin } from '../../lib/authenticate'
|
||||
import withSession from '../../lib/session'
|
||||
|
||||
async function loginHandler(req: any, res: any): Promise<void> {
|
||||
const { method } = req
|
||||
16
pages/api/logout.ts
Normal file
16
pages/api/logout.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import withSession from '../../lib/session'
|
||||
|
||||
async function loginHandler(req: any, res: any): Promise<void> {
|
||||
const { method } = req
|
||||
|
||||
switch (method) {
|
||||
case 'POST':
|
||||
req.session.destroy()
|
||||
res.json({ message: 'Logged out' })
|
||||
break
|
||||
default:
|
||||
res.setHeader('Allow', ['POST'])
|
||||
res.status(405).end(`Method ${method} Not Allowed`)
|
||||
}
|
||||
}
|
||||
export default withSession(loginHandler)
|
||||
@@ -1,9 +1,9 @@
|
||||
import React, { useState } from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
import Footer from '../../components/footer'
|
||||
import Header from '../../components/header'
|
||||
import Input from '../../components/input'
|
||||
import { getBaseURL } from '../../helpers/url'
|
||||
import Footer from '../components/footer'
|
||||
import Header from '../components/header'
|
||||
import Input from '../components/input'
|
||||
import { getBaseURL } from '../helpers/url'
|
||||
|
||||
export default function Login() {
|
||||
const router = useRouter()
|
||||
@@ -16,7 +16,7 @@ export default function Login() {
|
||||
event.preventDefault()
|
||||
|
||||
try {
|
||||
await fetch('/api/admin/login', {
|
||||
await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Reference in New Issue
Block a user