mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 00:31:25 +10:00
finalised client APIs and authentication method
This commit is contained in:
27
server/api/v1/client/auth/callback/index.get.ts
Normal file
27
server/api/v1/client/auth/callback/index.get.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import clientHandler from "~/server/internal/clients/handler";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const userId = await h3.context.session.getUserId(h3);
|
||||
if (!userId) throw createError({ statusCode: 403 });
|
||||
|
||||
const query = getQuery(h3);
|
||||
const providedClientId = query.id?.toString();
|
||||
if (!providedClientId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Provide client ID in request params as 'id'",
|
||||
});
|
||||
|
||||
const data = await clientHandler.fetchClientMetadata(
|
||||
providedClientId
|
||||
);
|
||||
if (!data)
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Request not found.",
|
||||
});
|
||||
|
||||
await clientHandler.attachUserId(providedClientId, userId);
|
||||
|
||||
return data;
|
||||
});
|
||||
Reference in New Issue
Block a user