You've already forked obsidian-visualiser
Starting to put back the server part. Currently the registration and login are almost ready.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import ".dotenv/config";
|
||||
import { Database } from "bun:sqlite";
|
||||
import { drizzle } from "drizzle-orm/bun-sqlite";
|
||||
import * as schema from '../db/schema';
|
||||
|
||||
export default function useDatabase()
|
||||
{
|
||||
const sqlite = new Database(process.env.DB_FILE);
|
||||
const db = drizzle({ client: sqlite });
|
||||
const sqlite = new Database(useRuntimeConfig().database);
|
||||
const db = drizzle({ client: sqlite, schema });
|
||||
|
||||
db.run("PRAGMA journal_mode = WAL;");
|
||||
|
||||
|
||||
4
composables/useToast.ts
Normal file
4
composables/useToast.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export default function useToast()
|
||||
{
|
||||
|
||||
}
|
||||
40
composables/useUserSession.ts
Normal file
40
composables/useUserSession.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { UserSession, UserSessionComposable } from '~/types/auth'
|
||||
|
||||
const useSessionState = () => useState<UserSession>('nuxt-session', () => ({}))
|
||||
const useAuthReadyState = () => useState('nuxt-auth-ready', () => false)
|
||||
|
||||
/**
|
||||
* Composable to get back the user session and utils around it.
|
||||
* @see https://github.com/atinux/nuxt-auth-utils
|
||||
*/
|
||||
export function useUserSession(): UserSessionComposable {
|
||||
const sessionState = useSessionState()
|
||||
const authReadyState = useAuthReadyState()
|
||||
return {
|
||||
ready: computed(() => authReadyState.value),
|
||||
loggedIn: computed(() => Boolean(sessionState.value.user)),
|
||||
user: computed(() => sessionState.value.user || null),
|
||||
session: sessionState,
|
||||
fetch,
|
||||
clear,
|
||||
}
|
||||
}
|
||||
|
||||
async function fetch() {
|
||||
const authReadyState = useAuthReadyState()
|
||||
useSessionState().value = await useRequestFetch()('/api/auth/session', {
|
||||
headers: {
|
||||
Accept: 'text/json',
|
||||
},
|
||||
retry: false,
|
||||
}).catch(() => ({}))
|
||||
if (!authReadyState.value) {
|
||||
authReadyState.value = true
|
||||
}
|
||||
}
|
||||
|
||||
async function clear() {
|
||||
await $fetch('/api/auth/session', { method: 'DELETE' })
|
||||
useSessionState().value = {}
|
||||
useRouter().go(0);
|
||||
}
|
||||
Reference in New Issue
Block a user