flameslayer
09/24/2023, 10:07 AMSuperTokensWrapper
in the root layout, root layout should be made a client component. But that just destroys the whole purpose of server components. Any workaround around it?
js
'use client'
import SuperTokensReact, { SuperTokensWrapper } from 'supertokens-auth-react'
import { frontendConfig } from '../config/frontendConfig'
if (typeof window !== 'undefined') {
// we only want to call this init function on the frontend, so we check typeof window !== 'undefined'
SuperTokensReact.init(frontendConfig())
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<SuperTokensWrapper>
<body suppressHydrationWarning={true}>{children}</body>
</SuperTokensWrapper>
</html>
)
}
ja3nyc
09/24/2023, 3:19 PMapp
|_ layout.tsx
|_ Providers.tsx
__Code Example__
Providers.tsx
typescript
'use client'
import SuperTokensReact, { SuperTokensWrapper } from 'supertokens-auth-react'
import { frontendConfig } from '../config/frontendConfig'
if (typeof window !== 'undefined') {
// we only want to call this init function on the frontend, so we check typeof window !== 'undefined'
SuperTokensReact.init(frontendConfig())
console.log("supertokens initialized")
}
export default function SuperTokenProvider({
children,
}: {
children: React.ReactNode
}) {
return(
<SuperTokensWrapper>
{children}
</SuperTokensWrapper>
)
}
layout.tsx
typescript
import './css/style.css'
import { Inter } from 'next/font/google'
import SuperTokenProvider from './Providers'
const inter = Inter({
subsets: ['latin'],
variable: '--font-inter',
display: 'swap'
})
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<SuperTokenProvider>
<body className={`${inter.variable} font-inter antialiased bg-white-900 text-black-900 tracking-tight`}>
<div className="flex flex-col min-h-screen overflow-hidden">
{children}
</div>
</body>
</SuperTokenProvider>
</html>
)
}
ja3nyc
09/24/2023, 3:19 PMflameslayer
09/25/2023, 11:17 AM