Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
fix: next-auth work w/ edgedb cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
doinel1a committed May 10, 2024
1 parent f7bb7b5 commit 51893c1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
10 changes: 2 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
# Server
AUTH_URL="http://localhost:3000"
AUTH_SECRET="" # You can generate a new secret on the command line with: openssl rand -base64 32
AUTH_EDGEDB_DSN=""
AUTH_GITHUB_ID=""
AUTH_GITHUB_SECRET=""

# Needed only in development env
EDGEDB_CLIENT_SECURITY="insecure_dev_mode"

# Needed when deploying to Vercel and EdgeDB is hosted on other Cloud Providers
EDGEDB_DSN="" # Must be the same as AUTH_EDGEDB_DSN
EDGEDB_CLIENT_TLS_SECURITY="insecure"
EDGEDB_INSTANCE=""
EDGEDB_SECRET_KEY=""
4 changes: 1 addition & 3 deletions auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { createClient } from 'edgedb';
import NextAuth from 'next-auth';
import Github from 'next-auth/providers/github';

import { env } from '@/env';

const client = createClient({ dsn: env.AUTH_EDGEDB_DSN });
const client = createClient();

export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: EdgeDBAdapter(client),
Expand Down
8 changes: 8 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';

import { auth } from 'auth';
import Link from 'next/link';

import Counter from '@/components/counter';
import GithubCorner from '@/components/github-corner';
import { Button } from '@/components/ui/button';

export default async function Home() {
const session = await auth();
Expand All @@ -20,6 +22,12 @@ export default async function Home() {
)}

<Counter />

<Button variant={session ? 'destructive' : 'default'} className='mt-5' asChild>
<Link href={session ? '/api/auth/signout' : '/api/auth/signin'}>
{session ? 'Sign out' : 'Sign in'}
</Link>
</Button>
</main>
);
}
14 changes: 4 additions & 10 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,27 @@ export const env = createEnv({
},
server: {
NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
AUTH_EDGEDB_DSN: z.string().url(),
AUTH_URL: z.preprocess(
(str) => process.env.VERCEL_URL ?? str,
process.env.VERCEL ? z.string() : z.string().url()
),
AUTH_SECRET: process.env.NODE_ENV === 'production' ? z.string() : z.string().optional(),
AUTH_GITHUB_ID: z.string(),
AUTH_GITHUB_SECRET: z.string(),
EDGEDB_DSN: process.env.NODE_ENV === 'development' ? z.string().optional() : z.string(),
EDGEDB_CLIENT_TLS_SECURITY:
process.env.NODE_ENV === 'development' ? z.string().optional() : z.string(),
EDGEDB_CLIENT_SECURITY:
process.env.NODE_ENV === 'development' ? z.string() : z.string().optional()
EDGEDB_INSTANCE: process.env.NODE_ENV === 'development' ? z.string().optional() : z.string(),
EDGEDB_SECRET_KEY: process.env.NODE_ENV === 'development' ? z.string() : z.string().optional()
},
runtimeEnv: {
// Client
// NEXT_PUBLIC_CLIENT_VAR: process.env.NEXT_PUBLIC_CLIENT_VAR,
// Server
NODE_ENV: process.env.NODE_ENV,
AUTH_EDGEDB_DSN: process.env.AUTH_EDGEDB_DSN,
AUTH_URL: process.env.AUTH_URL,
AUTH_SECRET: process.env.AUTH_SECRET,
AUTH_GITHUB_ID: process.env.AUTH_GITHUB_ID,
AUTH_GITHUB_SECRET: process.env.AUTH_GITHUB_SECRET,
EDGEDB_DSN: process.env.EDGEDB_DSN,
EDGEDB_CLIENT_TLS_SECURITY: process.env.EDGEDB_CLIENT_TLS_SECURITY,
EDGEDB_CLIENT_SECURITY: process.env.EDGEDB_CLIENT_SECURITY
EDGEDB_INSTANCE: process.env.EDGEDB_INSTANCE,
EDGEDB_SECRET_KEY: process.env.EDGEDB_SECRET_KEY
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
Expand Down

0 comments on commit 51893c1

Please sign in to comment.