add account deletion

This commit is contained in:
not-nullptr 2024-03-10 03:38:25 +00:00
parent c5686166d7
commit 5351c54d8d
9 changed files with 110 additions and 37 deletions

View file

@ -1,8 +1,16 @@
import type { CreateAccountRequest, CreateAccountResponse } from "$types/api";
import type { CreateAccountRequest, CreateAccountResponse, GetUserResponse } from "$types/api";
const apiUsers = {
async createAccount(body: CreateAccountRequest): Promise<CreateAccountResponse> {
return await SuyuAPI.req("POST", "/api/user/create-account", body);
return await SuyuAPI.req("POST", "/api/user", body);
},
async deleteAccount() {
return await SuyuAPI.req("DELETE", "/api/user");
},
async getUser(): Promise<GetUserResponse> {
return await SuyuAPI.req("GET", "/api/user");
},
} as const;

View file

@ -1,8 +1,12 @@
import { userRepo } from "$lib/server/repo";
import type { SuyuUser } from "$lib/server/schema";
import cookie from "cookie";
export async function useAuth(request: Request | string): Promise<SuyuUser | null> {
const apiKey = typeof request === "string" ? request : request.headers.get("Authorization");
const apiKey =
typeof request === "string"
? request
: cookie.parse(request.headers.get("cookie") || "").token;
if (!apiKey) {
return null;
}