Project import from github
This commit is contained in:
commit
0add58254d
179 changed files with 23756 additions and 0 deletions
45
app/stores/auth.ts
Normal file
45
app/stores/auth.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import { createAuthClient } from "better-auth/vue";
|
||||
|
||||
const authClient = createAuthClient();
|
||||
|
||||
export const useAuthStore = defineStore("useAuthStore", () => {
|
||||
const session = ref<Awaited<ReturnType<typeof authClient.useSession>> | null>(null);
|
||||
const lastError = ref<string | undefined>(undefined);
|
||||
|
||||
async function init() {
|
||||
const data = await authClient.useSession(useFetch);
|
||||
session.value = data;
|
||||
lastError.value = undefined;
|
||||
}
|
||||
|
||||
const user = computed(() => session.value?.data?.user);
|
||||
const loading = computed(() => session.value?.isPending);
|
||||
|
||||
async function signIn(email: string, password: string) {
|
||||
const { error } = await authClient.signIn.email({
|
||||
email,
|
||||
password,
|
||||
callbackURL: "/",
|
||||
});
|
||||
|
||||
if (error) {
|
||||
lastError.value = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
async function signOut() {
|
||||
await authClient.signOut({});
|
||||
navigateTo("/");
|
||||
}
|
||||
|
||||
return {
|
||||
init,
|
||||
lastError,
|
||||
loading,
|
||||
signIn,
|
||||
signOut,
|
||||
user,
|
||||
};
|
||||
});
|
||||
24
app/stores/breadcrumbs.ts
Normal file
24
app/stores/breadcrumbs.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { defineStore } from "pinia";
|
||||
|
||||
export interface BreadcrumbItem {
|
||||
label: string;
|
||||
to?: string;
|
||||
}
|
||||
|
||||
export const useBreadcrumbStore = defineStore("breadcrumb", {
|
||||
state: () => ({
|
||||
items: [] as BreadcrumbItem[],
|
||||
}),
|
||||
|
||||
actions: {
|
||||
setBreadcrumbs(items: BreadcrumbItem[]) {
|
||||
this.items = items;
|
||||
},
|
||||
addBreadcrumb(item: BreadcrumbItem) {
|
||||
this.items.push(item);
|
||||
},
|
||||
clear() {
|
||||
this.items = [];
|
||||
},
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue