Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global middleware option #114

Open
felix-dolderer opened this issue Mar 27, 2024 · 0 comments · May be fixed by #163
Open

Global middleware option #114

felix-dolderer opened this issue Mar 27, 2024 · 0 comments · May be fixed by #163
Labels
enhancement New feature or request

Comments

@felix-dolderer
Copy link
Contributor

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:

  1. Add a configuration option that adds a global middleware
  2. 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;
  }
});
@maige-app maige-app bot added the enhancement New feature or request label Mar 27, 2024
@felix-dolderer felix-dolderer linked a pull request Aug 16, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant