Skip to content

Commit

Permalink
fix: correct admin unsuccessful login to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
authcompanion committed Nov 12, 2023
1 parent 0393b74 commit beede9f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 6 additions & 1 deletion services/admin/users/login.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { verifyValueWithHash } from "../../../utils/credential.js";
import { verifyValueWithHash, secureCookie } from "../../../utils/credential.js";
import { makeAdminToken, makeAdminRefreshtoken } from "../../../utils/jwt.js";
import config from "../../../config.js";

Expand Down Expand Up @@ -52,6 +52,11 @@ export const loginHandler = async function (request, reply) {
expireDate.setTime(expireDate.getTime() + 7 * 24 * 60 * 60 * 1000); // TODO: Make configurable now, set to 7 days

reply.headers({
"set-cookie": [
`adminDashboardAccessToken=${adminAccessToken.token}; Path=/; Expires=${expireDate}; SameSite=${
config.SAMESITE
}; HttpOnly; ${secureCookie()}`,
],
"x-authc-app-origin": config.ADMINORIGIN,
});

Expand Down
5 changes: 2 additions & 3 deletions utils/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ export const authenticateWebAdminRequest = async function (request, reply) {
const cookies = parse(request.headers.cookie);

// Check if adminAccessToken token exists in the cookies
if (!cookies.adminAccessToken) {
if (!cookies.adminDashboardAccessToken) {
reply.redirect("/v1/admin/login");
throw { statusCode: "401", message: "Unauthorized, Please Login" };
}

// Validate the adminAccessToken token and get its payload
const fingerPrint = cookies["Fgp"];
const payload = await validateJWT(cookies.adminAccessToken, this.key, fingerPrint);
const payload = await validateJWT(cookies.adminDashboardAccessToken, this.key);

// Check if the payload contains the admin scope
if (!payload.scope.includes("admin")) {
Expand Down

0 comments on commit beede9f

Please sign in to comment.