mirror of
https://codeberg.org/MarkusThielker/finances.git
synced 2025-07-13 15:43:17 +00:00
N-FIN-79: remove lucia authentication components
This commit is contained in:
parent
6ba9a8872b
commit
c4146a36a4
10 changed files with 0 additions and 347 deletions
|
@ -1,41 +0,0 @@
|
|||
import { z } from 'zod';
|
||||
import { Argon2id } from 'oslo/password';
|
||||
import { lucia } from '@/auth';
|
||||
import { cookies } from 'next/headers';
|
||||
import { signInFormSchema } from '@/lib/form-schemas/signInFormSchema';
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { URL_HOME } from '@/lib/constants';
|
||||
import prisma from '@/prisma';
|
||||
|
||||
export default async function signIn({username, password}: z.infer<typeof signInFormSchema>): Promise<ActionResponse> {
|
||||
'use server';
|
||||
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
username: username.toLowerCase(),
|
||||
},
|
||||
});
|
||||
if (!existingUser) {
|
||||
return {
|
||||
type: 'error',
|
||||
message: 'Incorrect username or password',
|
||||
};
|
||||
}
|
||||
|
||||
const validPassword = await new Argon2id().verify(existingUser.password, password);
|
||||
if (!validPassword) {
|
||||
return {
|
||||
type: 'error',
|
||||
message: 'Incorrect username or password',
|
||||
};
|
||||
}
|
||||
|
||||
const session = await lucia.createSession(existingUser.id, {});
|
||||
const sessionCookie = lucia.createSessionCookie(session.id);
|
||||
cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes);
|
||||
return {
|
||||
type: 'success',
|
||||
message: 'Signed in successfully',
|
||||
redirect: URL_HOME,
|
||||
};
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
import { getSession, lucia } from '@/auth';
|
||||
import { cookies } from 'next/headers';
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
|
||||
export default async function signOut(): Promise<ActionResponse> {
|
||||
'use server';
|
||||
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return {
|
||||
type: 'error',
|
||||
message: 'You aren\'t signed in',
|
||||
};
|
||||
}
|
||||
|
||||
await lucia.invalidateSession(session.id);
|
||||
|
||||
const sessionCookie = lucia.createBlankSessionCookie();
|
||||
cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes);
|
||||
return {
|
||||
type: 'success',
|
||||
message: 'Signed out successfully',
|
||||
redirect: URL_SIGN_IN,
|
||||
};
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
import { z } from 'zod';
|
||||
import { Argon2id } from 'oslo/password';
|
||||
import { generateId } from 'lucia';
|
||||
import { lucia } from '@/auth';
|
||||
import { cookies } from 'next/headers';
|
||||
import { signUpFormSchema } from '@/lib/form-schemas/signUpFormSchema';
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { URL_HOME } from '@/lib/constants';
|
||||
import prisma from '@/prisma';
|
||||
|
||||
export default async function signUp({username, password}: z.infer<typeof signUpFormSchema>): Promise<ActionResponse> {
|
||||
'use server';
|
||||
|
||||
const hashedPassword = await new Argon2id().hash(password);
|
||||
const userId = generateId(15);
|
||||
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
username: username.toLowerCase(),
|
||||
},
|
||||
});
|
||||
|
||||
if (existingUser) {
|
||||
return {
|
||||
type: 'error',
|
||||
message: 'Username already exists',
|
||||
};
|
||||
}
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
id: userId,
|
||||
username: username,
|
||||
password: hashedPassword,
|
||||
},
|
||||
});
|
||||
|
||||
const session = await lucia.createSession(userId, {});
|
||||
const sessionCookie = lucia.createSessionCookie(session.id);
|
||||
cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes);
|
||||
return {
|
||||
type: 'success',
|
||||
message: 'Signed up successfully',
|
||||
redirect: URL_HOME,
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue