Skip to content

Commit

Permalink
feat(admin): enable dashboard logout
Browse files Browse the repository at this point in the history
  • Loading branch information
authcompanion committed Nov 19, 2023
1 parent 49542d9 commit c08bd5e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 1 addition & 2 deletions client/admin/dashboardPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,9 @@ <h2 class="text-lg font-medium text-gray-900" id="slide-over-title">Details</h2>
try {
// GET request to our logout endpoint /v1/admin/logout
let response = await fetch(`/v1/admin/logout`, {
method: "GET",
method: "DELETE",
headers: {
"Content-type": "application/json",
Authorization: `Bearer ${token}`,
},
});
// if the response is not ok, throw an error
Expand Down
3 changes: 3 additions & 0 deletions routes/admin.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { loginSchema } from "../services/admin/users/schema/loginSchema.js";
import { tokenRefreshHandler, tokenRefreshDeleteHandler } from "../services/admin/users/refresh.js";
import { refreshSchema } from "../services/admin/users/schema/refreshSchema.js";

import { logoutHandler } from "../services/admin/users/logout.js";

import { authenticateAdminRequest, authenticateWebAdminRequest } from "../utils/authenticate.js";

const adminRoutes = async function (fastify, options) {
Expand All @@ -28,6 +30,7 @@ const adminRoutes = async function (fastify, options) {
fastify.post("/login", loginSchema, loginHandler);
fastify.post("/refresh", refreshSchema, tokenRefreshHandler);
fastify.delete("/refresh", refreshSchema, tokenRefreshDeleteHandler);
fastify.delete("/logout", logoutHandler);

//admin web user interface routes
fastify.get("/dashboard", { onRequest: [authenticateWebAdminRequest] }, (request, reply) => {
Expand Down
14 changes: 14 additions & 0 deletions services/admin/users/logout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import config from "../../../config.js";

export const logoutHandler = async function (request, reply) {
try {
reply.headers({
"set-cookie": [`adminDashboardAccessToken=; Path=/; Expires=;`],
"x-authc-app-origin": config.ADMINORIGIN,
});

reply.code(204);
} catch (err) {
throw { statusCode: err.statusCode, message: err.message };
}
};

0 comments on commit c08bd5e

Please sign in to comment.