mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Cookie authentication.
This commit is contained in:
parent
0edf87941a
commit
5219582803
6 changed files with 337 additions and 29 deletions
19
pages/api/auth.js
Normal file
19
pages/api/auth.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { serialize } from 'cookie';
|
||||
import { hash, random, encrypt } from 'lib/crypto';
|
||||
|
||||
export default (req, res) => {
|
||||
const { password } = req.body;
|
||||
|
||||
if (password === process.env.PASSWORD) {
|
||||
const expires = new Date(Date.now() + 31536000000);
|
||||
const id = random();
|
||||
const value = encrypt(`${id}:${hash(id)}`);
|
||||
|
||||
const cookie = serialize('umami.auth', value, { expires, httpOnly: true });
|
||||
|
||||
res.setHeader('Set-Cookie', [cookie]);
|
||||
res.status(200).send('');
|
||||
} else {
|
||||
res.status(401).send('');
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue