mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Login/logout process.
This commit is contained in:
parent
0f0b1e39e7
commit
f947c7770b
10 changed files with 91 additions and 58 deletions
|
|
@ -1,11 +1,8 @@
|
|||
import { serialize } from 'cookie';
|
||||
import { checkPassword, createSecureToken } from 'lib/crypto';
|
||||
import { getAccount } from 'lib/db';
|
||||
import { allowPost } from 'lib/middleware';
|
||||
|
||||
export default async (req, res) => {
|
||||
await allowPost(req, res);
|
||||
|
||||
const { username, password } = req.body;
|
||||
|
||||
const account = await getAccount(username);
|
||||
|
|
@ -21,7 +18,7 @@ export default async (req, res) => {
|
|||
|
||||
res.setHeader('Set-Cookie', [cookie]);
|
||||
|
||||
res.status(200).send({ token });
|
||||
res.status(200).json({ token });
|
||||
} else {
|
||||
res.status(401).end();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { savePageView, saveEvent } from 'lib/db';
|
||||
import { allowPost } from 'lib/middleware';
|
||||
import { useCors } from 'lib/middleware';
|
||||
import checkSession from 'lib/session';
|
||||
import { createToken } from 'lib/crypto';
|
||||
|
||||
export default async (req, res) => {
|
||||
await allowPost(req, res);
|
||||
await useCors(req, res);
|
||||
|
||||
const session = await checkSession(req);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ export default async (req, res) => {
|
|||
|
||||
try {
|
||||
const payload = await verifySecureToken(token);
|
||||
res.status(200).send(payload);
|
||||
res.status(200).json(payload);
|
||||
} catch {
|
||||
res.status(400).end();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue