Revert "Upgrade linter and formatter to Ultracite" (#1226)
This commit is contained in:
parent
0e320b391d
commit
1aff7d9868
177 changed files with 8334 additions and 6943 deletions
|
|
@ -1,84 +1,84 @@
|
|||
"use server";
|
||||
'use server';
|
||||
|
||||
import { z } from "zod";
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createUser, getUser } from "@/lib/db/queries";
|
||||
import { createUser, getUser } from '@/lib/db/queries';
|
||||
|
||||
import { signIn } from "./auth";
|
||||
import { signIn } from './auth';
|
||||
|
||||
const authFormSchema = z.object({
|
||||
email: z.string().email(),
|
||||
password: z.string().min(6),
|
||||
});
|
||||
|
||||
export type LoginActionState = {
|
||||
status: "idle" | "in_progress" | "success" | "failed" | "invalid_data";
|
||||
};
|
||||
export interface LoginActionState {
|
||||
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 type RegisterActionState = {
|
||||
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'),
|
||||
});
|
||||
|
||||
const [user] = await getUser(validatedData.email);
|
||||
|
||||
if (user) {
|
||||
return { status: "user_exists" } as RegisterActionState;
|
||||
return { status: 'user_exists' } as RegisterActionState;
|
||||
}
|
||||
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,2 +1 @@
|
|||
// biome-ignore lint/performance/noBarrelFile: "Required"
|
||||
export { GET, POST } from "@/app/(auth)/auth";
|
||||
export { GET, POST } from '@/app/(auth)/auth';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { signIn } from "@/app/(auth)/auth";
|
||||
import { isDevelopmentEnvironment } from "@/lib/constants";
|
||||
import { signIn } from '@/app/(auth)/auth';
|
||||
import { isDevelopmentEnvironment } from '@/lib/constants';
|
||||
import { getToken } from 'next-auth/jwt';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const redirectUrl = searchParams.get("redirectUrl") || "/";
|
||||
const redirectUrl = searchParams.get('redirectUrl') || '/';
|
||||
|
||||
const token = await getToken({
|
||||
req: request,
|
||||
|
|
@ -14,8 +14,8 @@ export async function GET(request: Request) {
|
|||
});
|
||||
|
||||
if (token) {
|
||||
return NextResponse.redirect(new URL("/", request.url));
|
||||
return NextResponse.redirect(new URL('/', request.url));
|
||||
}
|
||||
|
||||
return signIn("guest", { redirect: true, redirectTo: redirectUrl });
|
||||
return signIn('guest', { redirect: true, redirectTo: redirectUrl });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import type { NextAuthConfig } from "next-auth";
|
||||
import type { NextAuthConfig } from 'next-auth';
|
||||
|
||||
export const authConfig = {
|
||||
pages: {
|
||||
signIn: "/login",
|
||||
newUser: "/",
|
||||
signIn: '/login',
|
||||
newUser: '/',
|
||||
},
|
||||
providers: [
|
||||
// added later in auth.ts since it requires bcrypt which is only compatible with Node.js
|
||||
|
|
|
|||
|
|
@ -1,22 +1,21 @@
|
|||
import { compare } from "bcrypt-ts";
|
||||
import NextAuth, { type DefaultSession } from "next-auth";
|
||||
import type { DefaultJWT } from "next-auth/jwt";
|
||||
import Credentials from "next-auth/providers/credentials";
|
||||
import { DUMMY_PASSWORD } from "@/lib/constants";
|
||||
import { createGuestUser, getUser } from "@/lib/db/queries";
|
||||
import { authConfig } from "./auth.config";
|
||||
import { compare } from 'bcrypt-ts';
|
||||
import NextAuth, { type DefaultSession } from 'next-auth';
|
||||
import Credentials from 'next-auth/providers/credentials';
|
||||
import { createGuestUser, getUser } from '@/lib/db/queries';
|
||||
import { authConfig } from './auth.config';
|
||||
import { DUMMY_PASSWORD } from '@/lib/constants';
|
||||
import type { DefaultJWT } from 'next-auth/jwt';
|
||||
|
||||
export type UserType = "guest" | "regular";
|
||||
export type UserType = 'guest' | 'regular';
|
||||
|
||||
declare module "next-auth" {
|
||||
declare module 'next-auth' {
|
||||
interface Session extends DefaultSession {
|
||||
user: {
|
||||
id: string;
|
||||
type: UserType;
|
||||
} & DefaultSession["user"];
|
||||
} & DefaultSession['user'];
|
||||
}
|
||||
|
||||
// biome-ignore lint/nursery/useConsistentTypeDefinitions: "Required"
|
||||
interface User {
|
||||
id?: string;
|
||||
email?: string | null;
|
||||
|
|
@ -24,7 +23,7 @@ declare module "next-auth" {
|
|||
}
|
||||
}
|
||||
|
||||
declare module "next-auth/jwt" {
|
||||
declare module 'next-auth/jwt' {
|
||||
interface JWT extends DefaultJWT {
|
||||
id: string;
|
||||
type: UserType;
|
||||
|
|
@ -58,24 +57,22 @@ export const {
|
|||
|
||||
const passwordsMatch = await compare(password, user.password);
|
||||
|
||||
if (!passwordsMatch) {
|
||||
return null;
|
||||
}
|
||||
if (!passwordsMatch) return null;
|
||||
|
||||
return { ...user, type: "regular" };
|
||||
return { ...user, type: 'regular' };
|
||||
},
|
||||
}),
|
||||
Credentials({
|
||||
id: "guest",
|
||||
id: 'guest',
|
||||
credentials: {},
|
||||
async authorize() {
|
||||
const [guestUser] = await createGuestUser();
|
||||
return { ...guestUser, type: "guest" };
|
||||
return { ...guestUser, type: 'guest' };
|
||||
},
|
||||
}),
|
||||
],
|
||||
callbacks: {
|
||||
jwt({ token, user }) {
|
||||
async jwt({ token, user }) {
|
||||
if (user) {
|
||||
token.id = user.id as string;
|
||||
token.type = user.type;
|
||||
|
|
@ -83,7 +80,7 @@ export const {
|
|||
|
||||
return token;
|
||||
},
|
||||
session({ session, token }) {
|
||||
async session({ session, token }) {
|
||||
if (session.user) {
|
||||
session.user.id = token.id;
|
||||
session.user.type = token.type;
|
||||
|
|
|
|||
|
|
@ -1,51 +1,52 @@
|
|||
"use client";
|
||||
'use client';
|
||||
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useActionState, useEffect, useState } from "react";
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useActionState, useEffect, useState } from 'react';
|
||||
import { toast } from '@/components/toast';
|
||||
|
||||
import { AuthForm } from "@/components/auth-form";
|
||||
import { SubmitButton } from "@/components/submit-button";
|
||||
import { toast } from "@/components/toast";
|
||||
import { type LoginActionState, login } from "../actions";
|
||||
import { AuthForm } from '@/components/auth-form';
|
||||
import { SubmitButton } from '@/components/submit-button';
|
||||
|
||||
import { login, type LoginActionState } from '../actions';
|
||||
import { useSession } from 'next-auth/react';
|
||||
|
||||
export default function Page() {
|
||||
const router = useRouter();
|
||||
|
||||
const [email, setEmail] = useState("");
|
||||
const [email, setEmail] = useState('');
|
||||
const [isSuccessful, setIsSuccessful] = useState(false);
|
||||
|
||||
const [state, formAction] = useActionState<LoginActionState, FormData>(
|
||||
login,
|
||||
{
|
||||
status: "idle",
|
||||
}
|
||||
status: 'idle',
|
||||
},
|
||||
);
|
||||
|
||||
const { update: updateSession } = useSession();
|
||||
|
||||
useEffect(() => {
|
||||
if (state.status === "failed") {
|
||||
if (state.status === 'failed') {
|
||||
toast({
|
||||
type: "error",
|
||||
description: "Invalid credentials!",
|
||||
type: 'error',
|
||||
description: 'Invalid credentials!',
|
||||
});
|
||||
} else if (state.status === "invalid_data") {
|
||||
} else if (state.status === 'invalid_data') {
|
||||
toast({
|
||||
type: "error",
|
||||
description: "Failed validating your submission!",
|
||||
type: 'error',
|
||||
description: 'Failed validating your submission!',
|
||||
});
|
||||
} else if (state.status === "success") {
|
||||
} else if (state.status === 'success') {
|
||||
setIsSuccessful(true);
|
||||
updateSession();
|
||||
router.refresh();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [state.status, router.refresh, updateSession]);
|
||||
}, [state.status]);
|
||||
|
||||
const handleSubmit = (formData: FormData) => {
|
||||
setEmail(formData.get("email") as string);
|
||||
setEmail(formData.get('email') as string);
|
||||
formAction(formData);
|
||||
};
|
||||
|
||||
|
|
@ -63,12 +64,12 @@ export default function Page() {
|
|||
<p className="mt-4 text-center text-gray-600 text-sm dark:text-zinc-400">
|
||||
{"Don't have an account? "}
|
||||
<Link
|
||||
className="font-semibold text-gray-800 hover:underline dark:text-zinc-200"
|
||||
href="/register"
|
||||
className="font-semibold text-gray-800 hover:underline dark:text-zinc-200"
|
||||
>
|
||||
Sign up
|
||||
</Link>
|
||||
{" for free."}
|
||||
{' for free.'}
|
||||
</p>
|
||||
</AuthForm>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,51 +1,53 @@
|
|||
"use client";
|
||||
'use client';
|
||||
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useActionState, useEffect, useState } from "react";
|
||||
import { AuthForm } from "@/components/auth-form";
|
||||
import { SubmitButton } from "@/components/submit-button";
|
||||
import { toast } from "@/components/toast";
|
||||
import { type RegisterActionState, register } from "../actions";
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useActionState, useEffect, useState } from 'react';
|
||||
|
||||
import { AuthForm } from '@/components/auth-form';
|
||||
import { SubmitButton } from '@/components/submit-button';
|
||||
|
||||
import { register, type RegisterActionState } from '../actions';
|
||||
import { toast } from '@/components/toast';
|
||||
import { useSession } from 'next-auth/react';
|
||||
|
||||
export default function Page() {
|
||||
const router = useRouter();
|
||||
|
||||
const [email, setEmail] = useState("");
|
||||
const [email, setEmail] = useState('');
|
||||
const [isSuccessful, setIsSuccessful] = useState(false);
|
||||
|
||||
const [state, formAction] = useActionState<RegisterActionState, FormData>(
|
||||
register,
|
||||
{
|
||||
status: "idle",
|
||||
}
|
||||
status: 'idle',
|
||||
},
|
||||
);
|
||||
|
||||
const { update: updateSession } = useSession();
|
||||
|
||||
useEffect(() => {
|
||||
if (state.status === "user_exists") {
|
||||
toast({ type: "error", description: "Account already exists!" });
|
||||
} else if (state.status === "failed") {
|
||||
toast({ type: "error", description: "Failed to create account!" });
|
||||
} else if (state.status === "invalid_data") {
|
||||
if (state.status === 'user_exists') {
|
||||
toast({ type: 'error', description: 'Account already exists!' });
|
||||
} else if (state.status === 'failed') {
|
||||
toast({ type: 'error', description: 'Failed to create account!' });
|
||||
} else if (state.status === 'invalid_data') {
|
||||
toast({
|
||||
type: "error",
|
||||
description: "Failed validating your submission!",
|
||||
type: 'error',
|
||||
description: 'Failed validating your submission!',
|
||||
});
|
||||
} else if (state.status === "success") {
|
||||
toast({ type: "success", description: "Account created successfully!" });
|
||||
} else if (state.status === 'success') {
|
||||
toast({ type: 'success', description: 'Account created successfully!' });
|
||||
|
||||
setIsSuccessful(true);
|
||||
updateSession();
|
||||
router.refresh();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [state.status, router.refresh, updateSession]);
|
||||
}, [state.status]);
|
||||
|
||||
const handleSubmit = (formData: FormData) => {
|
||||
setEmail(formData.get("email") as string);
|
||||
setEmail(formData.get('email') as string);
|
||||
formAction(formData);
|
||||
};
|
||||
|
||||
|
|
@ -61,14 +63,14 @@ export default function Page() {
|
|||
<AuthForm action={handleSubmit} defaultEmail={email}>
|
||||
<SubmitButton isSuccessful={isSuccessful}>Sign Up</SubmitButton>
|
||||
<p className="mt-4 text-center text-gray-600 text-sm dark:text-zinc-400">
|
||||
{"Already have an account? "}
|
||||
{'Already have an account? '}
|
||||
<Link
|
||||
className="font-semibold text-gray-800 hover:underline dark:text-zinc-200"
|
||||
href="/login"
|
||||
className="font-semibold text-gray-800 hover:underline dark:text-zinc-200"
|
||||
>
|
||||
Sign in
|
||||
</Link>
|
||||
{" instead."}
|
||||
{' instead.'}
|
||||
</p>
|
||||
</AuthForm>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue