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

Handle disabled state gracefully #552

Closed
peterbud opened this issue Oct 18, 2023 · 4 comments
Closed

Handle disabled state gracefully #552

peterbud opened this issue Oct 18, 2023 · 4 comments

Comments

@peterbud
Copy link

Describe the feature

nuxt-auth is working great in my project. However I'm using also histoire to build and test my components in isolation. In that case I set isEnabled: false for nuxt-auth in nuxt.config.ts

The problem is that in that case I get a bunch of errors everywhere where on the server side I have #auth import:
Could not resolve import "#auth"

Question: would it be possible to handle such cases more gracefully and avoid those errors, when the module is disabled?

Additional information

No response

@peterbud
Copy link
Author

I see similar issue has raised #454

@zoey-kaiser
Copy link
Member

zoey-kaiser commented Nov 6, 2023

Hi @peterbud!

So we do a bunch of testing in our projects as well. The way we approached it was to override the useAuth composable with our custom custom one made for testing.

This composable then also mocks a user account and returns demo functions that our testing suite can use.

You can add this into a testing file:

const pathToMocks = resolve('./nuxt-auth.ts')

nuxt.hook('imports:extend', (_imports) => {
  _imports.push({ name: 'useAuth', from: pathToMocks })
})

This will then overwrite the useAuth composable with the mocked one, allowing you to use it in testing.

Otherwise lets keep discussing how isEnabled works in #454. I hope the code snippet above helps you with your testing setup!

@peterbud
Copy link
Author

peterbud commented Nov 8, 2023

Thanks for the reply and the help. Can you point me to an example where this is used somewhere?

When I have tried to add this hook to nuxt.config.ts, I got the following error:

Duplicated imports "useAuth", the one from "[...]mock-useAuth.ts" has been ignored and "[....]/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sidebase/nuxt-auth/dist/runtime/composables/authjs/useAuth" is used

@zoey-kaiser
Copy link
Member

Can you point me to an example where this is used somewhere?

This is very dependent on your testing setup. I do not have much experience with historie, but I assume there is a setup file, similarly to how storybook does this. Inside this setup file you can then inject this new hook. You have to ensure it is only being used for your historie setup and does not override the actual composable in the app.

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

No branches or pull requests

2 participants