-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Desired Behaviour
It's be very nice to have an option to use the loggedIn middleware as a global middleware.
Current Situation
Currently the middleware needs to be added to each page individually or you need to create your own global middleware.
Creating your own global middleware either means copy / pasting the code from the module or importing directly from node_modules, because the middleware is not exposed so it could be directly imported.
Possible Implementations
I see two options to achieve the desired outcome:
- Add a configuration option that adds a global middleware
- Expose the middleware functions so they can be imported in a simple and typesafe way
Current workaround
My current implementation / workaround looks like this:
/*
* middleware/01-loggedIn.global.ts
*/
import hankoLoggedIn from "../node_modules/@nuxtjs/hanko/dist/runtime/middleware/logged-in";
export default defineNuxtRouteMiddleware(async (to, from) => {
// Don't trigger on same page navigation (changes to query or hash)
if (process.server || to.path !== from.path) {
const loggedInCheck = await hankoLoggedIn(to, from);
if (loggedInCheck) return loggedInCheck;
}
});
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request