mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Merge pull request #494 from Dokploy/fix/swagger-token
Fix/swagger token
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dokploy",
|
"name": "dokploy",
|
||||||
"version": "v0.9.0",
|
"version": "v0.9.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import type { IncomingMessage } from "node:http";
|
import type { IncomingMessage } from "node:http";
|
||||||
import { TimeSpan } from "lucia";
|
import { TimeSpan } from "lucia";
|
||||||
import { Lucia } from "lucia/dist/core.js";
|
import { Lucia } from "lucia/dist/core.js";
|
||||||
|
import { findAdminByAuthId } from "../api/services/admin";
|
||||||
|
import { findUserByAuthId } from "../api/services/user";
|
||||||
import { type ReturnValidateToken, adapter } from "./auth";
|
import { type ReturnValidateToken, adapter } from "./auth";
|
||||||
|
|
||||||
export const luciaToken = new Lucia(adapter, {
|
export const luciaToken = new Lucia(adapter, {
|
||||||
@@ -31,6 +33,16 @@ export const validateBearerToken = async (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const result = await luciaToken.validateSession(sessionId);
|
const result = await luciaToken.validateSession(sessionId);
|
||||||
|
|
||||||
|
if (result.user) {
|
||||||
|
if (result.user?.rol === "admin") {
|
||||||
|
const admin = await findAdminByAuthId(result.user.id);
|
||||||
|
result.user.adminId = admin.adminId;
|
||||||
|
} else if (result.user?.rol === "user") {
|
||||||
|
const userResult = await findUserByAuthId(result.user.id);
|
||||||
|
result.user.adminId = userResult.adminId;
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
session: result.session,
|
session: result.session,
|
||||||
...((result.user && {
|
...((result.user && {
|
||||||
|
|||||||
Reference in New Issue
Block a user