You've already forked obsidian-visualiser
Fix useContent not using cookies therefore skipping the auth step
This commit is contained in:
@@ -22,7 +22,7 @@ export function useContent(): ContentComposable {
|
||||
async function fetch(force: boolean) {
|
||||
const content = useContentState();
|
||||
if(content.value.length === 0 || force)
|
||||
content.value = await $fetch('/api/file/overview');
|
||||
content.value = await useRequestFetch()('/api/file/overview');
|
||||
}
|
||||
|
||||
async function get(path: string) {
|
||||
@@ -31,7 +31,7 @@ async function get(path: string) {
|
||||
const item = value.find(e => e.path === path);
|
||||
if(item)
|
||||
{
|
||||
item.content = await $fetch(`/api/file/content/${encodeURIComponent(path)}`);
|
||||
item.content = await useRequestFetch()(`/api/file/content/${encodeURIComponent(path)}`);
|
||||
}
|
||||
|
||||
content.value = value;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type { UserSession, UserSessionComposable } from '~/types/auth'
|
||||
import { useContent } from './useContent'
|
||||
|
||||
const useSessionState = () => useState<UserSession>('nuxt-session', () => ({}))
|
||||
const useAuthReadyState = () => useState('nuxt-auth-ready', () => false)
|
||||
const useContentFetch = (force: boolean) => useContent().fetch(force);
|
||||
|
||||
/**
|
||||
* Composable to get back the user session and utils around it.
|
||||
@@ -13,28 +15,27 @@ export function useUserSession(): UserSessionComposable {
|
||||
return {
|
||||
ready: computed(() => authReadyState.value),
|
||||
loggedIn: computed(() => Boolean(sessionState.value.user)),
|
||||
user: computed(() => sessionState.value.user || null),
|
||||
user: computed(() => sessionState.value.user ?? null),
|
||||
session: sessionState,
|
||||
fetch,
|
||||
clear,
|
||||
}
|
||||
}
|
||||
|
||||
async function fetch() {
|
||||
async function fetch(): Promise<boolean> {
|
||||
const authReadyState = useAuthReadyState()
|
||||
useSessionState().value = await useRequestFetch()('/api/auth/session', {
|
||||
headers: {
|
||||
Accept: 'text/json',
|
||||
},
|
||||
retry: false,
|
||||
}).catch(() => ({}))
|
||||
if (!authReadyState.value) {
|
||||
const sessionState = useSessionState()
|
||||
const loggedIn = Boolean(sessionState.value.user)
|
||||
sessionState.value = await useRequestFetch()('/api/auth/session').catch(() => ({}))
|
||||
if (!authReadyState.value)
|
||||
{
|
||||
authReadyState.value = true
|
||||
}
|
||||
return loggedIn !== Boolean(sessionState.value.user);
|
||||
}
|
||||
|
||||
async function clear() {
|
||||
await $fetch('/api/auth/session', { method: 'DELETE' })
|
||||
await useRequestFetch()('/api/auth/session', { method: 'DELETE' })
|
||||
useSessionState().value = {}
|
||||
useRouter().go(0);
|
||||
useRouter().go(0)
|
||||
}
|
||||
Reference in New Issue
Block a user