Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
packages/next-auth/src/next/utils.ts
Outdated
| const cookieHeader = serialize(name, value, options) | ||
| if (headers.has("Set-Cookie")) headers.append("Set-Cookie", cookieHeader) | ||
| else headers.set("Set-Cookie", cookieHeader) | ||
| // headers.set("Set-Cookie", cookieHeader) // TODO: Remove. Seems to be a bug with Headers in the runtime |
There was a problem hiding this comment.
Need to verify this in Next.js
There was a problem hiding this comment.
after upgrading to 13.3.0, I don't need this line anymore 👀
packages/next-auth/src/next/index.ts
Outdated
| return await NextAuthHandler(req as any, res as any, args[0]) | ||
|
|
||
| // REVIEW: req instanceof Request should return true on Route Handlers | ||
| // if (req instanceof Request) { |
There was a problem hiding this comment.
Need to verify this in Next.js
|
🎉 Experimental release published 📦️ on npm! pnpm add [email protected]yarn add [email protected]npm i [email protected] |
|
I am not sure if this is the right place for my comments but I tried this PR in my project and got the following error when trying to sign in with Google. (Note, this was working fine with the api route in the Here is the error: Here is how my When I had it in api route, I had no issues with CORS. |
27d0a62 to
d8b0e76
Compare
|
Interesting @benderillo, I'll check this out! Thanks for reporting! #6792 is a great place to report for the future, but I don't mind here either. UPDATE:
|
21d527a to
e4c2320
Compare
e4c2320 to
447425d
Compare
Seems to be included in next v13.3.0, which was just released |
packages/next-auth/src/next/utils.ts
Outdated
| const cookieHeader = serialize(name, value, options) | ||
| if (headers.has("Set-Cookie")) headers.append("Set-Cookie", cookieHeader) | ||
| else headers.set("Set-Cookie", cookieHeader) | ||
| // headers.set("Set-Cookie", cookieHeader) // TODO: Remove. Seems to be a bug with Headers in the runtime |
There was a problem hiding this comment.
after upgrading to 13.3.0, I don't need this line anymore 👀
|
Thank you for everyone's patience, this is now available in Remember, this is opt-in, |
I tried, installing this, and then testing it out, but unfortunately when I don't log in, hit cancel I get this error |
|
You're missing the provider at the end @enyelsequeira . It should be |
Oh, wow silly mistake! @juliusmarminge Thank you! |
|
I get "MISSING_NEXTAUTH_API_ROUTE_ERROR" with |
@bencehusi I installed the experimental version and it works without problems |
|
Does anyone have any idea how to use the import { SessionProvider } from "next-auth/react";
import "@/styles/globals.css";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
<SessionProvider session={session}>
<p>Hello, world!</p>
{children}
</SessionProvider>
</body>
</html>
);
}Also, https://authjs.dev/reference/react is gone, so that won't help me. EDIT: Turns out it's still at https://next-auth.js.org/getting-started/client, but it's still for Pages Router. |
|
UPDATE: I fixed my issue, turns out SessionProvider does Not need a session variable for App Router. layout.tsx: import AuthContext from "@/components/AuthContext";
import "@/styles/globals.css";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
<AuthContext>
<p>Hello, world!</p>
{children}
</AuthContext>
</body>
</html>
);
}components/AuthContext.tsx "use client";
import { SessionProvider } from "next-auth/react";
export interface AuthContextProps {
children: React.ReactNode;
}
export default function AuthContext({ children }: AuthContextProps) {
return <SessionProvider>{children}</SessionProvider>;
}See this comment for more information. |
The way your components are written, all of them are client components ( |
|
|
In your example above both layout and AuthContext are client, so no nesting occurs. The vanila |
|
Oh. I didn't use |
|
You wanna keep your layouts RSC (as per docs recommendation). export default async function DashboardLayout({
children,
}: {
children: React.ReactNode;
}) {
const session = await getServerSession();
return (
<SessionProvider session={session}>
{children}
</SessionProvider>
);
}"use client";
import { SessionProvider as NextAuthSessionProvider } from "next-auth/react";
import { type Session } from "next-auth";
import React from "react";
export default function SessionProvider({
children,
session,
}: {
children: React.ReactNode;
session?: Session;
}) {
return (
<NextAuthSessionProvider
session={session}
refetchInterval={500}
refetchOnWindowFocus
>
{children}
</NextAuthSessionProvider>
);
}Benefit is that you'll have a hydrated page with session available on first render/mount (no need for suspense/loading indicators, can even do auth checks). That's how I'm doing that currently, while awaiting some next-auth changes, prob. leveraging next 13.4 features. |
|
@Thinkscape 👍🏼 But this throws a Typescript error in the Layout: Type 'Session | null' is not assignable to type 'Session | undefined'. |
|
@dstroot you can change |
|
@balazsorban44 I ran a CLI experiment on a large JS/TS repo. I wrote up the exact collision here : Curious if this would be unacceptable or useful in your world. |



Adding support for Next.js Route Handlers https://beta.nextjs.org/docs/routing/route-handlers
Given that this is a significant Next.js feature and that
@auth/nextjsis not yet worked on, I decided to backport this tonext-auth, even if our main focus is the new Auth.js ecosystem.We do not want to stop shipping cool features like this to our current users!
Before merging, we need to test this a bit more (Created an experimental release, if anyone reading wants to test it #6777 (comment)), and add documentation.
I plan to add it under https://next-auth.js.org/configuration/initialization
Closes #6792