Limit the app to permitted emails
This commit is contained in:
@@ -21,3 +21,6 @@ AUTH_DISCORD_SECRET=""
|
||||
|
||||
# Drizzle
|
||||
DATABASE_URL="postgresql://postgres:password@localhost:5432/ls"
|
||||
|
||||
# Comma separated list of emails allowed to use the app
|
||||
PERMITTED_USERS=me@example.com,you@example.com
|
||||
@@ -17,6 +17,7 @@ export const env = createEnv({
|
||||
NODE_ENV: z
|
||||
.enum(["development", "test", "production"])
|
||||
.default("development"),
|
||||
PERMITTED_USERS: z.string(),
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -38,6 +39,7 @@ export const env = createEnv({
|
||||
AUTH_GOOGLE_SECRET: process.env.AUTH_GOOGLE_SECRET,
|
||||
DATABASE_URL: process.env.DATABASE_URL,
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
PERMITTED_USERS: process.env.PERMITTED_USERS,
|
||||
},
|
||||
/**
|
||||
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DrizzleAdapter } from "@auth/drizzle-adapter";
|
||||
import { type DefaultSession, type NextAuthConfig } from "next-auth";
|
||||
import Google from "next-auth/providers/google";
|
||||
import { env } from "~/env";
|
||||
|
||||
import { db } from "~/server/db";
|
||||
import {
|
||||
@@ -56,6 +57,8 @@ export const authConfig = {
|
||||
verificationTokensTable: verificationTokens,
|
||||
}),
|
||||
callbacks: {
|
||||
signIn: ({ user }) =>
|
||||
!!user?.email && env.PERMITTED_USERS.includes(user.email),
|
||||
session: ({ session, user }) => ({
|
||||
...session,
|
||||
user: {
|
||||
|
||||
Reference in New Issue
Block a user