Run prettier
This commit is contained in:
parent
e6806aaa54
commit
24cb81bce0
21 changed files with 4203 additions and 3520 deletions
|
|
@ -1,10 +1,10 @@
|
|||
"use server";
|
||||
'use server';
|
||||
|
||||
import { z } from "zod";
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createUser, getUser } from "@/db/queries";
|
||||
import { createUser, getUser } from '@/db/queries';
|
||||
|
||||
import { signIn } from "./auth";
|
||||
import { signIn } from './auth';
|
||||
|
||||
const authFormSchema = z.object({
|
||||
email: z.string().email(),
|
||||
|
|
@ -12,74 +12,74 @@ const authFormSchema = z.object({
|
|||
});
|
||||
|
||||
export interface LoginActionState {
|
||||
status: "idle" | "in_progress" | "success" | "failed" | "invalid_data";
|
||||
status: 'idle' | 'in_progress' | 'success' | 'failed' | 'invalid_data';
|
||||
}
|
||||
|
||||
export const login = async (
|
||||
_: LoginActionState,
|
||||
formData: FormData,
|
||||
formData: FormData
|
||||
): Promise<LoginActionState> => {
|
||||
try {
|
||||
const validatedData = authFormSchema.parse({
|
||||
email: formData.get("email"),
|
||||
password: formData.get("password"),
|
||||
email: formData.get('email'),
|
||||
password: formData.get('password'),
|
||||
});
|
||||
|
||||
await signIn("credentials", {
|
||||
await signIn('credentials', {
|
||||
email: validatedData.email,
|
||||
password: validatedData.password,
|
||||
redirect: false,
|
||||
});
|
||||
|
||||
return { status: "success" };
|
||||
return { status: 'success' };
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
return { status: "invalid_data" };
|
||||
return { status: 'invalid_data' };
|
||||
}
|
||||
|
||||
return { status: "failed" };
|
||||
return { status: 'failed' };
|
||||
}
|
||||
};
|
||||
|
||||
export interface RegisterActionState {
|
||||
status:
|
||||
| "idle"
|
||||
| "in_progress"
|
||||
| "success"
|
||||
| "failed"
|
||||
| "user_exists"
|
||||
| "invalid_data";
|
||||
| 'idle'
|
||||
| 'in_progress'
|
||||
| 'success'
|
||||
| 'failed'
|
||||
| 'user_exists'
|
||||
| 'invalid_data';
|
||||
}
|
||||
|
||||
export const register = async (
|
||||
_: RegisterActionState,
|
||||
formData: FormData,
|
||||
formData: FormData
|
||||
): Promise<RegisterActionState> => {
|
||||
try {
|
||||
const validatedData = authFormSchema.parse({
|
||||
email: formData.get("email"),
|
||||
password: formData.get("password"),
|
||||
email: formData.get('email'),
|
||||
password: formData.get('password'),
|
||||
});
|
||||
|
||||
let [user] = await getUser(validatedData.email);
|
||||
|
||||
if (user) {
|
||||
return { status: "user_exists" } as RegisterActionState;
|
||||
return { status: 'user_exists' } as RegisterActionState;
|
||||
} else {
|
||||
await createUser(validatedData.email, validatedData.password);
|
||||
await signIn("credentials", {
|
||||
await signIn('credentials', {
|
||||
email: validatedData.email,
|
||||
password: validatedData.password,
|
||||
redirect: false,
|
||||
});
|
||||
|
||||
return { status: "success" };
|
||||
return { status: 'success' };
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
return { status: "invalid_data" };
|
||||
return { status: 'invalid_data' };
|
||||
}
|
||||
|
||||
return { status: "failed" };
|
||||
return { status: 'failed' };
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { compare } from "bcrypt-ts";
|
||||
import NextAuth, { User, Session } from "next-auth";
|
||||
import Credentials from "next-auth/providers/credentials";
|
||||
import { compare } from 'bcrypt-ts';
|
||||
import NextAuth, { User, Session } from 'next-auth';
|
||||
import Credentials from 'next-auth/providers/credentials';
|
||||
|
||||
import { getUser } from "@/db/queries";
|
||||
import { getUser } from '@/db/queries';
|
||||
|
||||
import { authConfig } from "./auth.config";
|
||||
import { authConfig } from './auth.config';
|
||||
|
||||
interface ExtendedSession extends Session {
|
||||
user: User;
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
import { put } from "@vercel/blob";
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { put } from '@vercel/blob';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { auth } from "@/app/(auth)/auth";
|
||||
import { auth } from '@/app/(auth)/auth';
|
||||
|
||||
const FileSchema = z.object({
|
||||
file: z
|
||||
.instanceof(File)
|
||||
.refine((file) => file.size <= 5 * 1024 * 1024, {
|
||||
message: "File size should be less than 5MB",
|
||||
message: 'File size should be less than 5MB',
|
||||
})
|
||||
.refine(
|
||||
(file) =>
|
||||
["image/jpeg", "image/png", "application/pdf"].includes(file.type),
|
||||
['image/jpeg', 'image/png', 'application/pdf'].includes(file.type),
|
||||
{
|
||||
message: "File type should be JPEG, PNG, or PDF",
|
||||
},
|
||||
message: 'File type should be JPEG, PNG, or PDF',
|
||||
}
|
||||
),
|
||||
});
|
||||
|
||||
|
|
@ -23,19 +23,19 @@ export async function POST(request: Request) {
|
|||
const session = await auth();
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
if (request.body === null) {
|
||||
return new Response("Request body is empty", { status: 400 });
|
||||
return new Response('Request body is empty', { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const formData = await request.formData();
|
||||
const file = formData.get("file") as File;
|
||||
const file = formData.get('file') as File;
|
||||
|
||||
if (!file) {
|
||||
return NextResponse.json({ error: "No file uploaded" }, { status: 400 });
|
||||
return NextResponse.json({ error: 'No file uploaded' }, { status: 400 });
|
||||
}
|
||||
|
||||
const validatedFile = FileSchema.safeParse({ file });
|
||||
|
|
@ -43,7 +43,7 @@ export async function POST(request: Request) {
|
|||
if (!validatedFile.success) {
|
||||
const errorMessage = validatedFile.error.errors
|
||||
.map((error) => error.message)
|
||||
.join(", ");
|
||||
.join(', ');
|
||||
|
||||
return NextResponse.json({ error: errorMessage }, { status: 400 });
|
||||
}
|
||||
|
|
@ -53,17 +53,17 @@ export async function POST(request: Request) {
|
|||
|
||||
try {
|
||||
const data = await put(`${filename}`, fileBuffer, {
|
||||
access: "public",
|
||||
access: 'public',
|
||||
});
|
||||
|
||||
return NextResponse.json(data);
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: "Upload failed" }, { status: 500 });
|
||||
return NextResponse.json({ error: 'Upload failed' }, { status: 500 });
|
||||
}
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to process request" },
|
||||
{ status: 500 },
|
||||
{ error: 'Failed to process request' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { auth } from "@/app/(auth)/auth";
|
||||
import { getChatsByUserId } from "@/db/queries";
|
||||
import { auth } from '@/app/(auth)/auth';
|
||||
import { getChatsByUserId } from '@/db/queries';
|
||||
|
||||
export async function GET() {
|
||||
const session = await auth();
|
||||
|
||||
if (!session || !session.user) {
|
||||
return Response.json("Unauthorized!", { status: 401 });
|
||||
return Response.json('Unauthorized!', { status: 401 });
|
||||
}
|
||||
|
||||
const chats = await getChatsByUserId({ id: session.user.id! });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue