fix: load env variables

This commit is contained in:
lucas-neynar
2025-03-13 13:45:40 -07:00
parent 317e302e48
commit f040e9dcf9
7 changed files with 114 additions and 42 deletions

View File

@@ -14,7 +14,12 @@ export default async function RootLayout({
}: Readonly<{
children: React.ReactNode;
}>) {
console.log('Environment variables:');
console.log('NEXT_PUBLIC_URL:', process.env.NEXT_PUBLIC_URL);
console.log('NEXTAUTH_URL:', process.env.NEXTAUTH_URL);
const session = await getSession()
console.log('Session:', session);
return (
<html lang="en">

View File

@@ -10,6 +10,21 @@ declare module "next-auth" {
}
}
function getDomainFromUrl(urlString: string | undefined): string {
if (!urlString) {
console.warn('NEXTAUTH_URL is not set, using localhost:3000 as fallback');
return 'localhost:3000';
}
try {
const url = new URL(urlString);
return url.hostname;
} catch (error) {
console.error('Invalid NEXTAUTH_URL:', urlString, error);
console.warn('Using localhost:3000 as fallback');
return 'localhost:3000';
}
}
export const authOptions: AuthOptions = {
// Configure one or more authentication providers
providers: [
@@ -47,11 +62,13 @@ export const authOptions: AuthOptions = {
ethereum: viemConnector(),
});
const domain = getDomainFromUrl(process.env.NEXTAUTH_URL);
console.log('Using domain for auth:', domain);
const verifyResponse = await appClient.verifySignInMessage({
message: credentials?.message as string,
signature: credentials?.signature as `0x${string}`,
// question: what domain should this be?
domain: new URL(process.env.NEXTAUTH_URL ?? '').hostname,
domain,
nonce: csrfToken,
});
const { success, fid } = verifyResponse;