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

Add globalAppMiddleware similar to sidebase module #143

Open
1 task done
septatrix opened this issue Dec 7, 2023 · 5 comments
Open
1 task done

Add globalAppMiddleware similar to sidebase module #143

septatrix opened this issue Dec 7, 2023 · 5 comments
Labels
question Further information is requested

Comments

@septatrix
Copy link

Describe the feature

For many applications it is desirable to default to requiring authentication and have specific pages be able to opt out. Currently this is not possible and one has to manually add definePageMeta({ auth: true }); to every page. This is cumbersome and easy to forget. Please add a globalAppMiddleware similar to the one found in the sidebase package.

Additional information

  • Would you be willing to help implement this feature?
@Hebilicious
Copy link
Owner

You should be able to use layouts to avoid repeating logic for all pages that needs authentication.

https://nuxt.com/docs/guide/directory-structure/layouts

@Hebilicious Hebilicious added the question Further information is requested label Dec 24, 2023
@peterbud
Copy link

When I have tried to put a definePageMeta inside a layout file, I got the following warning:
definePageMeta() is a compiler-hint helper that is only usable inside the script block of a single file component which is also a page. Its arguments should be compiled away and passing it at runtime has no effect.

So I'm not sure what is the designated way to add definePageMeta and auth to the layouts.

Maybe if one of the playgrounds would use such technique that would help.

@Hebilicious
Copy link
Owner

Hebilicious commented Dec 25, 2023

When I have tried to put a definePageMeta inside a layout file, I got the following warning: definePageMeta() is a compiler-hint helper that is only usable inside the script block of a single file component which is also a page. Its arguments should be compiled away and passing it at runtime has no effect.

So I'm not sure what is the designated way to add definePageMeta and auth to the layouts.

Maybe if one of the playgrounds would use such technique that would help.

Oh right, this is a page only feature. In that case you have a couple other options :

I think documenting either of these would be preferable than adding a global option.

@peterbud
Copy link

Thanks for the quick reply. The global middleware seems to be the best solution.

I have a default layout which signs in the user if not already signed in, and that is applied without specifying any definePageMeta on every individual page. And there is another layout ("guest") which does not require authentication. For pages which does not require authentication (or opt out), one should define the guest layout using definePageMeta.

So I think this is indeed better than the global option.

@mrleblanc101
Copy link

I agree, this should be natively supported.
We shouldn't have to recreate this feature from scratch for every project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants