Skip to content

Commit

Permalink
🔒️ Disabled registration
Browse files Browse the repository at this point in the history
  • Loading branch information
ThijmenGThN committed Oct 25, 2023
1 parent 90836e8 commit e372cc0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 38 deletions.
4 changes: 4 additions & 0 deletions app/[locale]/(auth)/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default function Page() {

if (status == 400) return new Error(t('the-provided-address-does-not-meet-the-criteria-of-an-email-address'))
if (status == 403) return new Error(t('the-provided-email-address-is-already-taken'))

// Temp
if (status == 402) return new Error("Registration is disabled for now, soon you'll be able to upload your own themes!")

if (!ok) return new Error(t('sorry-something-unexpected-happened'))

setFormEmail(email)
Expand Down
78 changes: 40 additions & 38 deletions app/api/auth/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,45 @@ import eRegister from '@/emails/Register'

export async function POST(req: NextRequest) {

if (!(
process.env.NEXTAUTH_URL &&
process.env.NEXTAUTH_SECRET
)) return NextResponse.json('Internal server error.', { status: 500 })

try {
const { email } = await req.json()

if (!z.string()
.min(2)
.max(64)
.email()
.safeParse(email).success
) return NextResponse.json('The provided address does not meet the criteria of an email address.', { status: 400 })

if (await prisma.user.findUnique({ where: { email } })) return NextResponse.json('The provided email address is already taken.', { status: 403 })

const token = jwt.sign({ email }, process.env.NEXTAUTH_SECRET, { expiresIn: '1d' })

Email(
eRegister({
email,
link: process.env.NEXTAUTH_URL + '/en/register/' + token,
assets: { logoUrl: process.env.NEXTAUTH_URL + '/logo.webp' }
}),
{
to: email,
subject: 'Complete your registration'
}
)

return NextResponse.json('We have sent you an email to complete your registration.', { status: 200 })
}

catch (error) {
console.error(error)
return NextResponse.json('Internal server error, try again later.', { status: 500 })
}
return NextResponse.json('Disabled', { status: 402 })

// if (!(
// process.env.NEXTAUTH_URL &&
// process.env.NEXTAUTH_SECRET
// )) return NextResponse.json('Internal server error.', { status: 500 })

// try {
// const { email } = await req.json()

// if (!z.string()
// .min(2)
// .max(64)
// .email()
// .safeParse(email).success
// ) return NextResponse.json('The provided address does not meet the criteria of an email address.', { status: 400 })

// if (await prisma.user.findUnique({ where: { email } })) return NextResponse.json('The provided email address is already taken.', { status: 403 })

// const token = jwt.sign({ email }, process.env.NEXTAUTH_SECRET, { expiresIn: '1d' })

// Email(
// eRegister({
// email,
// link: process.env.NEXTAUTH_URL + '/en/register/' + token,
// assets: { logoUrl: process.env.NEXTAUTH_URL + '/logo.webp' }
// }),
// {
// to: email,
// subject: 'Complete your registration'
// }
// )

// return NextResponse.json('We have sent you an email to complete your registration.', { status: 200 })
// }

// catch (error) {
// console.error(error)
// return NextResponse.json('Internal server error, try again later.', { status: 500 })
// }

}

0 comments on commit e372cc0

Please sign in to comment.