linter fixes, env fixes
All checks were successful
Lint / Lint and Check (push) Successful in 51s

This commit is contained in:
2025-07-15 23:15:32 +02:00
parent f5fff9c52b
commit b02f5e6364
8 changed files with 169 additions and 66 deletions

View File

@@ -4,16 +4,17 @@ import { generateMemorableToken, isValidToken } from '@/lib/auth/tokens';
import { setTokenCookie, getTokenCookie } from '@/lib/auth/cookies';
import { eq } from 'drizzle-orm';
export async function GET(request: NextRequest) {
export async function GET() {
try {
// Check if user already has a token
const existingToken = await getTokenCookie();
if (existingToken) {
// Verify token exists in database
const [user] = await db.select().from(users).where(eq(users.token, existingToken));
const userRows = await db.select().from(users).where(eq(users.token, existingToken));
if (user) {
if (userRows.length > 0) {
const user = userRows[0];
return NextResponse.json({
authenticated: true,
token: existingToken,
@@ -31,20 +32,25 @@ export async function GET(request: NextRequest) {
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const body = (await request.json()) as { action: string; token?: string };
const { action, token } = body;
if (action === 'create') {
// Generate new token and create user
const newToken = generateMemorableToken();
const [newUser] = await db
const newUserRows = await db
.insert(users)
.values({
token: newToken,
})
.returning();
if (newUserRows.length === 0) {
throw new Error('Failed to create user');
}
const newUser = newUserRows[0];
await setTokenCookie(newToken);
return NextResponse.json({
@@ -67,9 +73,9 @@ export async function POST(request: NextRequest) {
}
// Check if token exists
const [user] = await db.select().from(users).where(eq(users.token, token));
const userRows = await db.select().from(users).where(eq(users.token, token));
if (!user) {
if (userRows.length === 0) {
return NextResponse.json(
{
success: false,
@@ -79,6 +85,7 @@ export async function POST(request: NextRequest) {
);
}
const user = userRows[0];
await setTokenCookie(token);
return NextResponse.json({