Restore Ultracite + fix sidebar (#1233)

This commit is contained in:
Hayden Bleasel 2025-09-21 11:02:31 -07:00 committed by GitHub
parent 8fbfc253fa
commit 947ed094a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
177 changed files with 6908 additions and 8306 deletions

View file

@ -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 interface LoginActionState {
status: 'idle' | 'in_progress' | 'success' | 'failed' | 'invalid_data';
}
export type 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 interface RegisterActionState {
export type 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" };
}
};

View file

@ -1 +1,2 @@
export { GET, POST } from '@/app/(auth)/auth';
// biome-ignore lint/performance/noBarrelFile: "Required"
export { GET, POST } from "@/app/(auth)/auth";

View file

@ -1,11 +1,11 @@
import { signIn } from '@/app/(auth)/auth';
import { isDevelopmentEnvironment } from '@/lib/constants';
import { getToken } from 'next-auth/jwt';
import { NextResponse } from 'next/server';
import { NextResponse } from "next/server";
import { getToken } from "next-auth/jwt";
import { signIn } from "@/app/(auth)/auth";
import { isDevelopmentEnvironment } from "@/lib/constants";
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 });
}

View file

@ -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

View file

@ -1,21 +1,22 @@
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';
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";
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;
@ -23,7 +24,7 @@ declare module 'next-auth' {
}
}
declare module 'next-auth/jwt' {
declare module "next-auth/jwt" {
interface JWT extends DefaultJWT {
id: string;
type: UserType;
@ -57,22 +58,24 @@ 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: {
async jwt({ token, user }) {
jwt({ token, user }) {
if (user) {
token.id = user.id as string;
token.type = user.type;
@ -80,7 +83,7 @@ export const {
return token;
},
async session({ session, token }) {
session({ session, token }) {
if (session.user) {
session.user.id = token.id;
session.user.type = token.type;

View file

@ -1,52 +1,51 @@
'use client';
"use client";
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useActionState, useEffect, useState } from 'react';
import { toast } from '@/components/toast';
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 { login, type LoginActionState } from '../actions';
import { useSession } from 'next-auth/react';
import { AuthForm } from "@/components/auth-form";
import { SubmitButton } from "@/components/submit-button";
import { toast } from "@/components/toast";
import { type LoginActionState, login } from "../actions";
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]);
}, [state.status, router.refresh, updateSession]);
const handleSubmit = (formData: FormData) => {
setEmail(formData.get('email') as string);
setEmail(formData.get("email") as string);
formAction(formData);
};
@ -64,12 +63,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
href="/register"
className="font-semibold text-gray-800 hover:underline dark:text-zinc-200"
href="/register"
>
Sign up
</Link>
{' for free.'}
{" for free."}
</p>
</AuthForm>
</div>

View file

@ -1,53 +1,51 @@
'use client';
"use client";
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';
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";
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]);
}, [state.status, router.refresh, updateSession]);
const handleSubmit = (formData: FormData) => {
setEmail(formData.get('email') as string);
setEmail(formData.get("email") as string);
formAction(formData);
};
@ -63,14 +61,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
href="/login"
className="font-semibold text-gray-800 hover:underline dark:text-zinc-200"
href="/login"
>
Sign in
</Link>
{' instead.'}
{" instead."}
</p>
</AuthForm>
</div>