mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
init: nuxt adapter
This commit is contained in:
31
examples/nuxt/app/composables/useTodoActions.ts
Normal file
31
examples/nuxt/app/composables/useTodoActions.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { DB } from "bknd";
|
||||
|
||||
type Todo = DB["todos"];
|
||||
|
||||
export const useTodoActions = () => {
|
||||
const fetchTodos = () =>
|
||||
$fetch<{ limit: number; todos: Array<Todo>; total: number }>("/todos", {
|
||||
method: "POST",
|
||||
body: { action: "get" },
|
||||
});
|
||||
|
||||
const createTodo = (title: string) =>
|
||||
$fetch("/todos", {
|
||||
method: "POST",
|
||||
body: { action: "create", data: { title } },
|
||||
});
|
||||
|
||||
const deleteTodo = (todo: Todo) =>
|
||||
$fetch("/todos", {
|
||||
method: "POST",
|
||||
body: { action: "delete", data: { id: todo.id } },
|
||||
});
|
||||
|
||||
const toggleTodo = (todo: Todo) =>
|
||||
$fetch("/todos", {
|
||||
method: "POST",
|
||||
body: { action: "toggle", data: todo },
|
||||
});
|
||||
|
||||
return { fetchTodos, createTodo, deleteTodo, toggleTodo };
|
||||
};
|
||||
6
examples/nuxt/app/composables/useUser.ts
Normal file
6
examples/nuxt/app/composables/useUser.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { User } from "bknd";
|
||||
|
||||
export const useUser = () => {
|
||||
const getUser = () => $fetch("/api/auth/me") as Promise<{ user: User }>;
|
||||
return { getUser };
|
||||
};
|
||||
Reference in New Issue
Block a user