Shaki
Shaki
BABetter Auth
Created by Shaki on 5/13/2025 in #help
session null in nextjs route handler
I found the fix. You have to pass the headers to the api call inside of your server component
3 replies
BABetter Auth
Created by aswnss on 5/15/2025 in #help
Next Hono session is empty
Does your fetch have credentials include on the client?
import { hc } from "hono/client";
import type { AppType } from "./server"; // Your Hono app type

const client = hc<AppType>("http://localhost:8787/", {
fetch: ((input, init) => {
return fetch(input, {
...init,
credentials: "include" // Required for sending cookies cross-origin
});
}) satisfies typeof fetch,
});

// Now your client requests will include credentials
const response = await client.someProtectedEndpoint.$get();
import { hc } from "hono/client";
import type { AppType } from "./server"; // Your Hono app type

const client = hc<AppType>("http://localhost:8787/", {
fetch: ((input, init) => {
return fetch(input, {
...init,
credentials: "include" // Required for sending cookies cross-origin
});
}) satisfies typeof fetch,
});

// Now your client requests will include credentials
const response = await client.someProtectedEndpoint.$get();
36 replies
BABetter Auth
Created by aswnss on 5/15/2025 in #help
Next Hono session is empty
Ok. My only other guess will be trying this. I see the server is returning a success but for whatever reason next isn't reading the cookie
const session = await authClient.getSession({)
const session = await authClient.getSession({)
36 replies
BABetter Auth
Created by aswnss on 5/15/2025 in #help
Next Hono session is empty
Okay cool. Can you try logging in again?
36 replies
BABetter Auth
Created by aswnss on 5/15/2025 in #help
Next Hono session is empty
try awaiting the authClient in the frontend
import { authClient } from "@/lib/auth-client";
import { headers } from "next/headers";
export default async function ProfilePage() {
const session = await authClient.getSession({
fetchOptions: {
headers: await headers()
}
})
return (
<div>
{JSON.stringify(session)}
</div>
);
}
import { authClient } from "@/lib/auth-client";
import { headers } from "next/headers";
export default async function ProfilePage() {
const session = await authClient.getSession({
fetchOptions: {
headers: await headers()
}
})
return (
<div>
{JSON.stringify(session)}
</div>
);
}
and try updating auth config
crossSubDomainCookies: {
enabled: true,
domains: ["localhost:3000"],
},
crossSubDomainCookies: {
enabled: true,
domains: ["localhost:3000"],
},
36 replies
BABetter Auth
Created by aswnss on 5/15/2025 in #help
Next Hono session is empty
add the advanced option to your auth config and replace the domain/trustedOrigins with your client url
export const auth = betterAuth({
advanced: {
crossSubDomainCookies: {
enabled: true,
domain: ".example.com", // Domain with a leading period
},
defaultCookieAttributes: {
secure: true,
httpOnly: true,
sameSite: "none", // Allows CORS-based cookie sharing across subdomains
partitioned: true, // New browser standards will mandate this for foreign cookies
},
},
trustedOrigins: [
'https://example.com',
'https://app1.example.com',
'https://app2.example.com',
],
})
export const auth = betterAuth({
advanced: {
crossSubDomainCookies: {
enabled: true,
domain: ".example.com", // Domain with a leading period
},
defaultCookieAttributes: {
secure: true,
httpOnly: true,
sameSite: "none", // Allows CORS-based cookie sharing across subdomains
partitioned: true, // New browser standards will mandate this for foreign cookies
},
},
trustedOrigins: [
'https://example.com',
'https://app1.example.com',
'https://app2.example.com',
],
})
36 replies
BABetter Auth
Created by aswnss on 5/15/2025 in #help
Next Hono session is empty
Did you add the nextjs setCookie plugin? https://www.better-auth.com/docs/integrations/next and also specify which domains should have access to the cookie https://www.better-auth.com/docs/concepts/cookies#cross-subdomain-cookies
36 replies
BABetter Auth
Created by Shaki on 2/7/2025 in #help
Email does not exist on user table
Still getting same error. The field "email" does not exist in the schema for the model "user". Please update your schema
4 replies
BABetter Auth
Created by Shaki on 2/7/2025 in #help
Email does not exist on user table
I ran the migrations and can even see the email field when I open drizzle studio on the users table
4 replies