Changed JWT implementation.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { serialize } from 'cookie';
|
||||
import { checkPassword, createToken, secret } from 'lib/crypto';
|
||||
import { checkPassword, createSecureToken } from 'lib/crypto';
|
||||
import { getAccount } from 'lib/db';
|
||||
|
||||
export default async (req, res) => {
|
||||
@@ -9,7 +9,7 @@ export default async (req, res) => {
|
||||
|
||||
if (account && (await checkPassword(password, account.password))) {
|
||||
const { user_id, username, is_admin } = account;
|
||||
const token = await createToken({ user_id, username, is_admin });
|
||||
const token = await createSecureToken({ user_id, username, is_admin });
|
||||
const expires = new Date(Date.now() + 31536000000);
|
||||
const cookie = serialize('umami.auth', token, { expires, httpOnly: true });
|
||||
|
||||
|
||||
12
pages/api/verify.js
Normal file
12
pages/api/verify.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { verifySecureToken } from 'lib/crypto';
|
||||
|
||||
export default async (req, res) => {
|
||||
const { token } = req.body;
|
||||
|
||||
try {
|
||||
const payload = await verifySecureToken(token);
|
||||
res.status(200).send(payload);
|
||||
} catch {
|
||||
res.status(400).send('');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user