Skip to content

Commit 94e99ba

Browse files
fix(examples): add SessionProvider layout for auth-next route
Fix "useSession must be wrapped in SessionProvider" error by adding a dedicated layout.tsx for the /connect-with-auth-next route. The layout wraps the route with SessionProvider and passes the server-side session, following Next.js App Router best practices. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 427efe0 commit 94e99ba

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

  • examples/passport/wallets-connect-with-nextjs/app/connect-with-auth-next
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { SessionProvider } from 'next-auth/react';
2+
import { auth } from '@/lib/auth-next';
3+
4+
export default async function ConnectWithAuthNextLayout({
5+
children,
6+
}: {
7+
children: React.ReactNode;
8+
}) {
9+
const session = await auth();
10+
11+
return <SessionProvider session={session}>{children}</SessionProvider>;
12+
}

examples/passport/wallets-connect-with-nextjs/app/connect-with-auth-next/page.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import { Button, Heading, Body } from '@biom3/react';
44
import { useImmutableSession, useLogin, useLogout } from '@imtbl/auth-next-client';
55
import { connectWallet } from '@imtbl/wallet';
66
import { useState } from 'react';
7-
import { SessionProvider } from 'next-auth/react';
87

9-
function ConnectWithAuthNextContent() {
8+
export default function ConnectWithAuthNext() {
109
const { isAuthenticated, session, getUser } = useImmutableSession();
1110
const { loginWithPopup, isLoggingIn, error: loginError } = useLogin();
1211
const { logout, isLoggingOut, error: logoutError } = useLogout();
@@ -150,11 +149,3 @@ function ConnectWithAuthNextContent() {
150149
</div>
151150
);
152151
}
153-
154-
export default function ConnectWithAuthNext() {
155-
return (
156-
<SessionProvider>
157-
<ConnectWithAuthNextContent />
158-
</SessionProvider>
159-
);
160-
}

0 commit comments

Comments
 (0)