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

Commit

Permalink
Feature/vercel edge config (mckaywrigley#1232)
Browse files Browse the repository at this point in the history
* Added vercel edge config to login-page for login whitelisting

* Fixed some labels and remove debug console.log
  • Loading branch information
sebiweise authored and bpalagi committed Jan 28, 2024
1 parent d047a0d commit 360eecd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
22 changes: 17 additions & 5 deletions app/[locale]/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createServerClient } from "@supabase/ssr"
import { Metadata } from "next"
import { cookies, headers } from "next/headers"
import { redirect } from "next/navigation"
import { get } from '@vercel/edge-config';

export const metadata: Metadata = {
title: "Login"
Expand Down Expand Up @@ -62,9 +63,14 @@ export default async function Login({
const email = formData.get("email") as string
const password = formData.get("password") as string

if (process.env.EMAIL_DOMAIN_WHITELIST) {
const emailDomainWhitelist =
process.env.EMAIL_DOMAIN_WHITELIST?.split(",") ?? []
if (process.env.EMAIL_DOMAIN_WHITELIST || process.env.EDGE_CONFIG) {
let patternsString = process.env.EMAIL_DOMAIN_WHITELIST;

if (process.env.EDGE_CONFIG)
patternsString = await get<string>('EMAIL_DOMAIN_WHITELIST');

const emailDomainWhitelist = patternsString?.split(",") ?? []

if (
emailDomainWhitelist.length > 0 &&
!emailDomainWhitelist.includes(email.split("@")[1])
Expand All @@ -75,8 +81,14 @@ export default async function Login({
}
}

if (process.env.EMAIL_WHITELIST) {
const emailWhitelist = process.env.EMAIL_WHITELIST?.split(",") ?? []
if (process.env.EMAIL_WHITELIST || process.env.EDGE_CONFIG) {
let patternsString = process.env.EMAIL_WHITELIST;

if (process.env.EDGE_CONFIG)
patternsString = await get<string>('EMAIL_WHITELIST');

const emailWhitelist = patternsString?.split(",") ?? []

if (emailWhitelist.length > 0 && !emailWhitelist.includes(email)) {
return redirect(
`/login?message=Email ${email} is not allowed to sign up.`
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@supabase/supabase-js": "^2.38.4",
"@tabler/icons-react": "^2.40.0",
"@vercel/analytics": "^1.1.1",
"@vercel/edge-config": "^0.4.1",
"@xenova/transformers": "^2.13.4",
"ai": "^2.2.31",
"class-variance-authority": "^0.7.0",
Expand Down
4 changes: 2 additions & 2 deletions public/locales/de/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"Ask anything. Type \"/\" for prompts, \"@\" for files, and \"#\" for tools.": "test",
"Quick Settings": "test"
"Ask anything. Type \"/\" for prompts, \"@\" for files, and \"#\" for tools.": "Ask anything. Type \"/\" for prompts, \"@\" for files, and \"#\" for tools.",
"Quick Settings": "Quick Settings"
}

0 comments on commit 360eecd

Please sign in to comment.