Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use authjs env vars #162

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions SETUP-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ This guide will help you set up your own instance of Supermemory. This is necces
### web

1. You need to create OAuth credentials for Google which is need for auth.js (nextauth). Visit https://developers.google.com/identity/protocols/oauth2 to learn more and https://console.cloud.google.com/apis/dashboard to create a new project and OAuth credentials. You need to set the redirect URL to `http://localhost:3000/api/auth/callback/google` for development. You can also set the redirect URL to your own domain if you are deploying the app.
2. Create a `.dev.vars` file in `apps/web` with the following content:
2. You can use `apps/web/.dev.vars.example` as a template. Create a `.dev.vars` file in `apps/web` with the following content:

```bash
GOOGLE_CLIENT_ID="" // required
GOOGLE_CLIENT_SECRET="" // required
NEXTAUTH_SECRET="" // generate by running `openssl rand -base64 32`
AUTH_URL="http://localhost:3000"
AUTH_SECRET="" // generate by running `openssl rand -base64 32`
AUTH_GOOGLE_ID="" // required
AUTH_GOOGLE_SECRET="" // required
DATABASE_URL='database.sqlite'
NEXTAUTH_URL='http://localhost:3000'
BACKEND_SECURITY_KEY="" // used to authenticate with the backend. generate a random string using `openssl rand -base64 32`
BACKEND_BASE_URL="http://localhost:8686"
```
Expand Down
7 changes: 7 additions & 0 deletions apps/web/.dev.vars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
AUTH_URL="http://localhost:3000"
AUTH_SECRET=""
AUTH_GOOGLE_ID=""
AUTH_GOOGLE_SECRET=""
DATABASE_URL='database.sqlite'
BACKEND_SECURITY_KEY=""
BACKEND_BASE_URL="http://localhost:8686"
4 changes: 2 additions & 2 deletions apps/web/app/api/ensureAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export async function ensureAuth(req: NextRequest) {
if (
!(
authUserData.audience.split("-")[0] ===
process.env.GOOGLE_CLIENT_ID.split("-")[0] &&
process.env.AUTH_GOOGLE_ID.split("-")[0] &&
authUserData.issued_to.split("-")[0] ===
process.env.GOOGLE_CLIENT_ID.split("-")[0]
process.env.AUTH_GOOGLE_ID.split("-")[0]
)
) {
console.log(
Expand Down
7 changes: 4 additions & 3 deletions apps/web/cf-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
declare global {
namespace NodeJS {
interface ProcessEnv extends CloudflareEnv {
GOOGLE_CLIENT_ID: string;
GOOGLE_CLIENT_SECRET: string;
AUTH_SECRET: string;
AUTH_URL: string;
AUTH_SECRET: string;
AUTH_GOOGLE_ID: string;
AUTH_GOOGLE_SECRET: string;

R2_ENDPOINT: string;
R2_ACCESS_KEY_ID: string;
Expand Down
9 changes: 2 additions & 7 deletions apps/web/server/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NextAuth, { NextAuthResult } from "next-auth";
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { db } from "./db";
Expand All @@ -18,10 +18,5 @@ export const {
sessionsTable: sessions,
verificationTokensTable: verificationTokens,
}),
providers: [
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
providers: [Google],
});
6 changes: 3 additions & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"dev": {
"env": [
"NODE_ENV=development",
"GOOGLE_CLIENT_ID",
"GOOGLE_CLIENT_SECRET",
"NEXTAUTH_SECRET",
"AUTH_GOOGLE_ID",
"AUTH_GOOGLE_SECRET",
"AUTH_SECRET",
"R2_ENDPOINT",
"R2_ACCESS_ID",
"R2_SECRET_KEY",
Expand Down