mirror of
https://github.com/BillyOutlast/drop.git
synced 2026-02-04 00:31:17 +01:00
fix: client webtoken fix
This commit is contained in:
@@ -1,37 +1,21 @@
|
||||
import { APITokenMode } from "~/prisma/client/enums";
|
||||
import { DateTime } from "luxon";
|
||||
import type { UserACL } from "~/server/internal/acls";
|
||||
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import { CLIENT_WEBTOKEN_ACLS } from "~/server/plugins/04.auth-init";
|
||||
|
||||
export default defineClientEventHandler(
|
||||
async (h3, { fetchUser, fetchClient, clientId }) => {
|
||||
const user = await fetchUser();
|
||||
const client = await fetchClient();
|
||||
|
||||
const acls: UserACL = [
|
||||
"read",
|
||||
"store:read",
|
||||
"object:read",
|
||||
"settings:read",
|
||||
|
||||
"collections:read",
|
||||
"collections:new",
|
||||
"collections:add",
|
||||
"collections:remove",
|
||||
"collections:delete",
|
||||
|
||||
"library:add",
|
||||
"library:remove"
|
||||
];
|
||||
|
||||
const token = await prisma.aPIToken.create({
|
||||
data: {
|
||||
name: `${client.name} Web Access Token ${DateTime.now().toISO()}`,
|
||||
clientId,
|
||||
userId: user.id,
|
||||
mode: APITokenMode.Client,
|
||||
acls,
|
||||
acls: CLIENT_WEBTOKEN_ACLS,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
import authManager from "~/server/internal/auth";
|
||||
import prisma from "../internal/db/database";
|
||||
import { APITokenMode } from "~/prisma/client/enums";
|
||||
import type { UserACL } from "../internal/acls";
|
||||
|
||||
export const CLIENT_WEBTOKEN_ACLS: UserACL = [
|
||||
"read",
|
||||
"store:read",
|
||||
"object:read",
|
||||
"settings:read",
|
||||
|
||||
"collections:read",
|
||||
"collections:new",
|
||||
"collections:add",
|
||||
"collections:remove",
|
||||
"collections:delete",
|
||||
|
||||
"library:add",
|
||||
"library:remove",
|
||||
];
|
||||
|
||||
export default defineNitroPlugin(async () => {
|
||||
await authManager.init();
|
||||
|
||||
await prisma.aPIToken.updateMany({
|
||||
where: {
|
||||
mode: APITokenMode.Client,
|
||||
},
|
||||
data: {
|
||||
acls: CLIENT_WEBTOKEN_ACLS,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user