This commit is contained in:
Dan Mihailescu 2024-12-15 18:17:02 -05:00
parent f0f32d71fc
commit ce0d940953
35 changed files with 62 additions and 66 deletions

View file

@ -13,4 +13,4 @@ const config = {
options: {}
}
};
export default config;
export default config;

View file

@ -10,4 +10,4 @@ const preview = {
}
};
export default preview;
export default preview;

View file

@ -16,4 +16,4 @@ h2 {
h3 {
@apply font-display text-2xl;
}
}

3
src/app.d.ts vendored
View file

@ -2,10 +2,9 @@
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
interface Locals {
user: import("lucia").User | null;
user: import('lucia').User | null;
session: import('lucia').Session | null;
}
// interface PageData {}

View file

@ -27,4 +27,4 @@
});
</script>
<Story name="Default" args={{ label: 'Button', size: 'normal', primary: true }} />
<Story name="Default" args={{ label: 'Button', size: 'normal', primary: true }} />

View file

@ -48,4 +48,4 @@
.button--secondary {
@apply bg-blue-600 text-white;
}
</style>
</style>

View file

@ -40,4 +40,4 @@
<Story name="Text" args={{ label: 'Text', name: 'text', type: 'text' }} />
<Story name="Password" args={{ label: 'Password', name: 'pass', type: 'password' }} />
<Story name="Email" args={{ label: 'Email', name: 'email', type: 'email' }} />
<Story name="Email" args={{ label: 'Email', name: 'email', type: 'email' }} />

View file

@ -33,4 +33,4 @@
all: unset;
@apply text-lg;
}
</style>
</style>

View file

@ -9,4 +9,4 @@
});
</script>
<Story name="Default" args={{}} />
<Story name="Default" args={{}} />

View file

@ -48,4 +48,4 @@
transform: rotate(-360deg);
}
}
</style>
</style>

View file

@ -9,4 +9,4 @@
});
</script>
<Story name="Default" args={{ title: 'Storybook' }} />
<Story name="Default" args={{ title: 'Storybook' }} />

View file

@ -28,4 +28,4 @@
.navbar h2 {
@apply text-xl;
}
</style>
</style>

View file

@ -1 +1 @@
export * from './Navbar.svelte';
export * from './Navbar.svelte';

View file

@ -1,2 +1,2 @@
// place files you want to import through the `$lib` alias in this folder.
export * from './components';
export * from './components';

View file

@ -21,4 +21,4 @@ export const LoadConfig = (): Configuration => {
};
};
export const Config = LoadConfig();
export const Config = LoadConfig();

View file

@ -20,4 +20,4 @@ export const yogaLogger: YogaLogger = {
// @ts-expect-error types dont match
logger.error(...args);
}
};
};

View file

@ -1,32 +1,32 @@
import { Lucia } from "lucia";
import { PrismaAdapter } from "@lucia-auth/adapter-prisma";
import { PrismaClient } from "@prisma/client";
import { Lucia } from 'lucia';
import { PrismaAdapter } from '@lucia-auth/adapter-prisma';
import { PrismaClient } from '@prisma/client';
const client = new PrismaClient();
const adapter = new PrismaAdapter(client.session, client.user)
const adapter = new PrismaAdapter(client.session, client.user);
// expect error (see next section)
export const auth = new Lucia(adapter, {
sessionCookie: {
attributes: {
secure: process.env.NODE_ENV === "production"
}
},
getUserAttributes: (attributes)=>{
return {
email: attributes.email
}
}
sessionCookie: {
attributes: {
secure: process.env.NODE_ENV === 'production'
}
},
getUserAttributes: (attributes) => {
return {
email: attributes.email
};
}
});
declare module "lucia" {
interface Register {
Lucia: typeof Lucia;
DatabaseUserAttributes: DatabaseUserAttributes
}
declare module 'lucia' {
interface Register {
Lucia: typeof Lucia;
DatabaseUserAttributes: DatabaseUserAttributes;
}
}
interface DatabaseUserAttributes {
email: string
email: string;
}
export type Auth = typeof auth;
export type Auth = typeof auth;

View file

@ -25,4 +25,4 @@ export const builder = new SchemaBuilder<PothosType>({
// warn when not using a query parameter correctly
onUnusedQuery: process.env.NODE_ENV === 'production' ? null : 'warn'
}
});
});

View file

@ -1 +1 @@
export * from './schema';
export * from './schema';

View file

@ -11,4 +11,4 @@ export const DateScalar = builder.scalarType('Date', {
}
return new Date(date);
}
});
});

View file

@ -5,4 +5,4 @@ export type Scalars = {
Input: Date;
Output: Date;
};
};
};

View file

@ -15,4 +15,4 @@ import './Scalars';
import './posts';
import './users';
export const Schema = builder.toSchema();
export const Schema = builder.toSchema();

View file

@ -107,4 +107,4 @@ builder.mutationFields((t) => ({
return post;
}
})
}));
}));

View file

@ -80,4 +80,4 @@ builder.mutationFields((t) => ({
return post;
}
})
}));
}));

View file

@ -1,3 +1,3 @@
import { PrismaClient } from '@prisma/client';
export const prisma = new PrismaClient();
export const prisma = new PrismaClient();

View file

@ -4,4 +4,4 @@ import type { YogaInitialContext } from 'graphql-yoga';
export const Context = (initialContext: YogaInitialContext) => ({
...initialContext,
config: Config
});
});

View file

@ -1,2 +1,2 @@
export * from './context';
export * from './server';
export * from './server';

View file

@ -11,4 +11,4 @@ export const Yoga = createYoga<RequestEvent>({
// Let Yoga use sveltekit's Response object
fetchAPI: { Response },
logging: yogaLogger
});
});

View file

@ -11,4 +11,4 @@
.layout {
@apply h-screen w-screen animate-fade bg-slate-100;
}
</style>
</style>

View file

@ -15,4 +15,4 @@ export async function load(event) {
return {
authenticated: !!user
};
}
}

View file

@ -21,4 +21,4 @@
.site-loader {
@apply flex h-screen w-screen flex-col items-center justify-center gap-6;
}
</style>
</style>

View file

@ -1,3 +1,3 @@
import { Yoga } from '$lib/server/yoga';
export { Yoga as GET, Yoga as POST };
export { Yoga as GET, Yoga as POST };

View file

@ -5,4 +5,4 @@
</script>
<Navbar title="Svelte" />
{@render children()}
{@render children()}

View file

@ -1,7 +1,7 @@
import { logger } from '$lib/server/logger';
import { prisma } from '$lib/server/prisma';
import { error, redirect, type Actions } from '@sveltejs/kit';
import { Argon2id } from "oslo/password"
import { Argon2id } from 'oslo/password';
import { auth } from '$lib/server/lucia.js';
export const actions = {
@ -19,12 +19,12 @@ export const actions = {
logger.error('User not found! ${user}');
return error(401);
}
const pw = form.get('password') as string;
if(!pw) {
return error(401, 'Password is required')
const password = form.get('password') as string;
if (!password) {
return error(401, 'Password is required');
}
const validPassword = await new Argon2id().verify(user.password,pw);
if(!validPassword) {
const validPassword = await new Argon2id().verify(user.password, password);
if (!validPassword) {
return error(400, 'Password is incorrect!');
}
const session = await auth.createSession(user.id, []);
@ -36,14 +36,12 @@ export const actions = {
redirect(302, '/');
},
register: async (event) => {
const form = await event.request.formData();
if (!form.has('email') || !form.has('name') || !form.has('password')) {
return error(400);
}
const hashedPassword = await new Argon2id().hash(form.get('password') as string)
const hashedPassword = await new Argon2id().hash(form.get('password') as string);
const user = await prisma.user.create({
data: {
email: form.get('email') as string,
@ -61,6 +59,5 @@ export const actions = {
maxAge: 120
});
redirect(302, '/');
}
} satisfies Actions;
} satisfies Actions;

View file

@ -22,4 +22,4 @@ export default {
},
plugins: [typography]
} satisfies Config;
} satisfies Config;