Implemented email verification
This commit is contained in:
17
lib/db.ts
17
lib/db.ts
@@ -1,10 +1,17 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
import * as process from 'process'
|
||||
import { env } from '@/lib/utils'
|
||||
|
||||
declare global {
|
||||
var prisma: PrismaClient | undefined
|
||||
const prismaClientSingleton = () => {
|
||||
return new PrismaClient()
|
||||
}
|
||||
|
||||
export const db = globalThis.prisma || new PrismaClient()
|
||||
declare global {
|
||||
var prismaGlobal: undefined | ReturnType<typeof prismaClientSingleton>
|
||||
}
|
||||
|
||||
const db = globalThis.prismaGlobal ?? prismaClientSingleton()
|
||||
|
||||
export default db
|
||||
|
||||
if (env('NODE_ENV') !== 'production') globalThis.prismaGlobal = db
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalThis.prisma = db
|
||||
@@ -2,7 +2,7 @@ import { v4 as uuid } from 'uuid'
|
||||
import {
|
||||
VERIFICATION_TOKEN_EXPIRATION_DURATION,
|
||||
} from '@/config/auth'
|
||||
import { db } from '@/lib/db'
|
||||
import db from '@/lib/db'
|
||||
import { getVerificationTokenByEmail } from '@/data/verification-token'
|
||||
|
||||
export const generateVerificationToken = async (email: string) => {
|
||||
|
||||
29
lib/translate.ts
Normal file
29
lib/translate.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { type loc, locales, fallbackLocale } from '@/config/locales'
|
||||
|
||||
export const __c = async (key: string | null | undefined, locale?: loc) => {
|
||||
key = (key ?? '').trim()
|
||||
if (key.length === 0) return key
|
||||
|
||||
if (!locales.includes(locale ??= fallbackLocale)) {
|
||||
locale = fallbackLocale
|
||||
}
|
||||
|
||||
let data: any = await import(`@/locales/custom.${locale}`).then(({ default: data }) => data).catch(() => false)
|
||||
if (data === false) return key
|
||||
|
||||
const x = key.split('.')
|
||||
let c: number = x.length
|
||||
|
||||
if (c === 1) {
|
||||
return data.hasOwn(x[0]) && typeof data[x[0]] === 'string' ? data[x[0]] : key
|
||||
}
|
||||
|
||||
for (let i in x) {
|
||||
if (data.hasOwn(x[i])) {
|
||||
data = data[x[i]]
|
||||
c--
|
||||
}
|
||||
}
|
||||
|
||||
return c === 0 ? data : key
|
||||
}
|
||||
11
lib/utils.ts
11
lib/utils.ts
@@ -1,7 +1,8 @@
|
||||
import { type ClassValue, clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import { LC } from '@/config/locales'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
import { env as dotEnv } from 'process'
|
||||
|
||||
export function cn (...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
@@ -10,3 +11,11 @@ export function cn (...inputs: ClassValue[]) {
|
||||
export function lc (locale: string) {
|
||||
return LC.filter(lc => locale === lc.code)[0]
|
||||
}
|
||||
|
||||
export function env (variable: string, defaultValue?: string | ''): string {
|
||||
return (dotEnv[variable] ?? defaultValue ?? '')
|
||||
}
|
||||
|
||||
export function tr (el: React.ReactNode, params: object) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user