mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Handle website delete. Added response helper functions.
This commit is contained in:
parent
0a411a9ad6
commit
c4b75e4aec
31 changed files with 314 additions and 96 deletions
|
|
@ -2,6 +2,7 @@ import { serialize } from 'cookie';
|
|||
import { checkPassword, createSecureToken } from 'lib/crypto';
|
||||
import { getAccount } from 'lib/db';
|
||||
import { AUTH_COOKIE_NAME } from 'lib/constants';
|
||||
import { ok, unauthorized } from 'lib/response';
|
||||
|
||||
export default async (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
|
|
@ -19,8 +20,8 @@ export default async (req, res) => {
|
|||
|
||||
res.setHeader('Set-Cookie', [cookie]);
|
||||
|
||||
return res.status(200).json({ token });
|
||||
return ok(res, { token });
|
||||
}
|
||||
|
||||
return res.status(401).end();
|
||||
return unauthorized(res);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { serialize } from 'cookie';
|
||||
import { AUTH_COOKIE_NAME } from 'lib/constants';
|
||||
import { redirect } from 'lib/response';
|
||||
|
||||
export default async (req, res) => {
|
||||
const cookie = serialize(AUTH_COOKIE_NAME, '', {
|
||||
|
|
@ -8,9 +9,7 @@ export default async (req, res) => {
|
|||
maxAge: 0,
|
||||
});
|
||||
|
||||
res.statusCode = 303;
|
||||
res.setHeader('Set-Cookie', [cookie]);
|
||||
res.setHeader('Location', '/login');
|
||||
|
||||
return res.end();
|
||||
return redirect(res, '/login');
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, unauthorized } from 'lib/response';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
if (req.auth) {
|
||||
return res.status(200).json(req.auth);
|
||||
return ok(res, req.auth);
|
||||
}
|
||||
|
||||
return res.status(401).end();
|
||||
return unauthorized(res);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue