Importing non-react based modules that depend on the window. #16602
-
NEXT.JS Question. Hey, I am working on implementing auth for a site and the auth provider instance that I have to work with relies on browser storage being present in order to function properly. Every time that I import this module however I get errors related to the window not being present. I figured that I might try the Does anyone have an idea of how to import a module that relies on the window that isn't a react component? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You had the right idea with next/dynamic and
const MyAuthComponent = dynamic(
() => import('../components/MyAuthComponent'),
{ ssr: false }
)
export default function Index() {
return (
<MyAuthComponent />
)
}
import AuthLibrary from 'auth-library'
export default function MyAuthComponent() {
// use your authLibrary
return <div>auth component</div>
} |
Beta Was this translation helpful? Give feedback.
-
This is what I ended up going with as well. Thanks! |
Beta Was this translation helpful? Give feedback.
This is what I ended up going with as well. Thanks!