initial commit
This commit is contained in:
44
src/lib/server/auth.ts
Normal file
44
src/lib/server/auth.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { Lucia } from 'lucia';
|
||||
import { dev } from '$app/environment';
|
||||
import { DrizzlePostgreSQLAdapter } from '@lucia-auth/adapter-drizzle';
|
||||
import { db } from './db';
|
||||
import { sessions, users } from './db/schema';
|
||||
import { Gitea } from 'arctic';
|
||||
import { GITEA_BASE_URL, GITEA_CLIENT_ID, GITEA_CLIENT_SECRET } from '$env/static/private';
|
||||
|
||||
const adapter = new DrizzlePostgreSQLAdapter(db, sessions, users);
|
||||
|
||||
export const lucia = new Lucia(adapter, {
|
||||
sessionCookie: {
|
||||
attributes: {
|
||||
secure: !dev
|
||||
}
|
||||
},
|
||||
getUserAttributes: (attributes) => {
|
||||
return {
|
||||
username: attributes.username,
|
||||
giteaId: attributes.giteaId,
|
||||
avatarUrl: attributes.avatarUrl
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
declare module 'lucia' {
|
||||
interface Register {
|
||||
Lucia: typeof lucia;
|
||||
DatabaseUserAttributes: DatabaseUserAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
interface DatabaseUserAttributes {
|
||||
username: string;
|
||||
giteaId: number;
|
||||
avatarUrl: string;
|
||||
}
|
||||
|
||||
export const gitea = new Gitea(
|
||||
GITEA_BASE_URL,
|
||||
GITEA_CLIENT_ID,
|
||||
GITEA_CLIENT_SECRET,
|
||||
'http://localhost:5173/login/gitea/callback'
|
||||
);
|
||||
Reference in New Issue
Block a user