fix(auth): small issues with login process
This commit is contained in:
parent
4f8ebc7dd9
commit
c4b1bb2f65
3 changed files with 5 additions and 4 deletions
|
|
@ -40,14 +40,14 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
|||
return makeResponse("failed", "otp.failed.timeout");
|
||||
|
||||
// get the Otp sercret from the db
|
||||
let otpSecret = this.db.getUserOtpSecret(dJwt.who);
|
||||
if (isNullish(otpSecret))
|
||||
let user = this.db.getUserFromName(dJwt.who);
|
||||
if (isNullish(user?.otp))
|
||||
// oops, either no user, or user without otpSecret
|
||||
// fuck off
|
||||
return makeResponse("failed", "otp.failed.noSecret");
|
||||
|
||||
// good lets now verify the token you gave us is the correct one...
|
||||
let otpHandle = new Otp({ secret: otpSecret });
|
||||
let otpHandle = new Otp({ secret: user.otp });
|
||||
|
||||
let now = Date.now();
|
||||
const tokens = [
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
|||
"/api/auth/whoami",
|
||||
{ schema: { response: { "2xx": WhoAmIRes } }, config: { requireAuth: true } },
|
||||
async function(req, _res) {
|
||||
if (isNullish(req.authUser))
|
||||
return makeResponse("failure", "whoami.failure.generic")
|
||||
return makeResponse("success", "whoami.success", { name: req.authUser.name })
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue