mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-27 22:27:23 +08:00
chore: moved exampled to frontend
This commit is contained in:
56
frontend/examples/nextjs/util/TodoClient.ts
Normal file
56
frontend/examples/nextjs/util/TodoClient.ts
Normal file
@ -0,0 +1,56 @@
|
||||
export interface Todo {
|
||||
todoID?: string;
|
||||
description: string;
|
||||
checked: boolean;
|
||||
}
|
||||
|
||||
export type Todos = Todo[];
|
||||
|
||||
export class TodoClient {
|
||||
api: string;
|
||||
|
||||
constructor(api: string) {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
addTodo(todo: Todo) {
|
||||
return fetch(`${this.api}/todo`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(todo),
|
||||
});
|
||||
}
|
||||
|
||||
listTodos() {
|
||||
return fetch(`${this.api}/todo`, {
|
||||
credentials: "include",
|
||||
});
|
||||
}
|
||||
|
||||
patchTodo(id: string, checked: boolean) {
|
||||
return fetch(`${this.api}/todo/${id}`, {
|
||||
method: "PATCH",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({checked}),
|
||||
});
|
||||
}
|
||||
|
||||
deleteTodo(id: string) {
|
||||
return fetch(`${this.api}/todo/${id}`, {
|
||||
method: "DELETE",
|
||||
credentials: "include",
|
||||
});
|
||||
}
|
||||
|
||||
logout() {
|
||||
return fetch(`${this.api}/logout`, {
|
||||
credentials: "include",
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user