mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
78338205a3
* checkpoint * fix pg schema * fix mysql schema * change property names
24 lines
732 B
JavaScript
24 lines
732 B
JavaScript
import { ok, unauthorized, badRequest, checkPassword, createSecureToken } from 'next-basics';
|
|
import { getAccountByUsername } from 'queries/admin/account/getAccountByUsername';
|
|
import { secret } from 'lib/crypto';
|
|
|
|
export default async (req, res) => {
|
|
const { username, password } = req.body;
|
|
|
|
if (!username || !password) {
|
|
return badRequest(res);
|
|
}
|
|
|
|
const account = await getAccountByUsername(username);
|
|
|
|
if (account && checkPassword(password, account.password)) {
|
|
const { id, username, isAdmin, accountUuid } = account;
|
|
const user = { userId: id, username, isAdmin, accountUuid };
|
|
const token = createSecureToken(user, secret());
|
|
|
|
return ok(res, { token, user });
|
|
}
|
|
|
|
return unauthorized(res);
|
|
};
|