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

[Next 13] 'window' is not defined #19

Closed
erickriva opened this issue Mar 19, 2023 · 4 comments
Closed

[Next 13] 'window' is not defined #19

erickriva opened this issue Mar 19, 2023 · 4 comments

Comments

@erickriva
Copy link

erickriva commented Mar 19, 2023

It happens in a Next 13 page (app folder) marked as a client component with use client directive.

Imported as: import * as webauthn from "@passwordless-id/webauthn";
Used as: {webauthn.client.isAvailable() && "available"}

@dagnelies
Copy link
Collaborator

dagnelies commented Mar 19, 2023

I'm not very familiar with nextjs and your project. I can just say that isAvailable() is meant to be called at runtimevin the browser (to discover the browser/platform capabilities). It is not something to be called server-side and pre-rendered. So of course the window object is necessary at that point. The issue as far as I understand is unrelated to this library but because you use isAvailable() to pre-render server side. Feel free to reopen the issue if I missed something.

@dagnelies
Copy link
Collaborator

...that goes for all the webauthn.client.* stuff of course. It's for the browser at runtime, not for server side rendering.

@erickriva
Copy link
Author

vercel/next.js#47028 (comment)
Searching for similar discussions, I've found this sentence: "Client components are rendered on the server too.". Therefore, window is undefined in first render.

To solve it on Next project, there's need for a useState and a useEffect, adding complexity to codebase to every component where this lib is called.

Can't this lib check for typeof window !== undefined before to do what's necessary? Obviously, if complexity don't increase as much as I mentioned.

@dagnelies
Copy link
Collaborator

dagnelies commented Mar 19, 2023

Without window, the lib obviously cannot check if WebAuthn is available for that browser. It doesn't even make sense.

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