mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-15 09:11:21 +10:00
feat: allow client-based web tokens
This commit is contained in:
31
server/api/v1/client/user/webtoken.post.ts
Normal file
31
server/api/v1/client/user/webtoken.post.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { APITokenMode } from "@prisma/client";
|
||||
import { DateTime } from "luxon";
|
||||
import { UserACL } from "~/server/internal/acls";
|
||||
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineClientEventHandler(
|
||||
async (h3, { fetchUser, fetchClient, clientId }) => {
|
||||
const user = await fetchUser();
|
||||
const client = await fetchClient();
|
||||
|
||||
const acls: UserACL = [
|
||||
"read",
|
||||
"store:read",
|
||||
"collections:read",
|
||||
"object:read",
|
||||
];
|
||||
|
||||
const token = await prisma.aPIToken.create({
|
||||
data: {
|
||||
name: `${client.name} Web Access Token ${DateTime.now().toISO()}`,
|
||||
clientId,
|
||||
userId: user.id,
|
||||
mode: APITokenMode.Client,
|
||||
acls,
|
||||
},
|
||||
});
|
||||
|
||||
return token.token;
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user