import { user } from '@/auth-schema'
import { auth } from '@/app/utils/auth'
import { db } from '@/app/utils/db'
// Route Handler for setting up our default user.
export async function GET() {
const adminEmail = process.env.RULE0_INITIAL_EMAIL
const adminUsername = process.env.RULE0_INITIAL_EMAIL
const adminPassword = process.env.RULE0_INITIAL_EMAIL
try {
if (adminEmail && adminUsername && adminPassword) {
const existing = await db.select().from(user).limit(1)
if (existing.length > 0) {
return new Response(`Unable to make initial user, already exists!`, { status: 400 })
} else {
const user = await auth.api.createUser({
body: {
name: process.env.RULE0_INITIAL_USERNAME!,
email: process.env.RULE0_INITIAL_EMAIL!,
password: process.env.RULE0_INITIAL_PASSWORD!,
role: 'admin'
}
})
return new Response('User added successfully!', { status: 200 })
}
} else {
return new Response(
`Unable to make new user due to lack of env variables! (RULE0_INITIAL_USERNAME/EMAIL/PASSWORD)!`,
{ status: 400 }
)
}
} catch (error) {
return new Response(`Unable to make new user ${error}`, { status: 400 })
}
}
import { user } from '@/auth-schema'
import { auth } from '@/app/utils/auth'
import { db } from '@/app/utils/db'
// Route Handler for setting up our default user.
export async function GET() {
const adminEmail = process.env.RULE0_INITIAL_EMAIL
const adminUsername = process.env.RULE0_INITIAL_EMAIL
const adminPassword = process.env.RULE0_INITIAL_EMAIL
try {
if (adminEmail && adminUsername && adminPassword) {
const existing = await db.select().from(user).limit(1)
if (existing.length > 0) {
return new Response(`Unable to make initial user, already exists!`, { status: 400 })
} else {
const user = await auth.api.createUser({
body: {
name: process.env.RULE0_INITIAL_USERNAME!,
email: process.env.RULE0_INITIAL_EMAIL!,
password: process.env.RULE0_INITIAL_PASSWORD!,
role: 'admin'
}
})
return new Response('User added successfully!', { status: 200 })
}
} else {
return new Response(
`Unable to make new user due to lack of env variables! (RULE0_INITIAL_USERNAME/EMAIL/PASSWORD)!`,
{ status: 400 }
)
}
} catch (error) {
return new Response(`Unable to make new user ${error}`, { status: 400 })
}
}