refactor(api): ♻️ Remove useless authorization checks

This commit is contained in:
Jesse Wierzbinski 2024-12-30 19:38:41 +01:00
parent dc12b269f5
commit 09f30db83a
No known key found for this signature in database
59 changed files with 103 additions and 839 deletions

View file

@ -40,14 +40,6 @@ export default (plugin: PluginType): void => {
},
},
},
401: {
description: "Unauthorized",
content: {
"application/json": {
schema: ErrorSchema,
},
},
},
404: {
description: "Account not found",
content: {
@ -62,10 +54,6 @@ export default (plugin: PluginType): void => {
const { id: issuerId } = context.req.valid("param");
const { user } = context.get("auth");
if (!user) {
throw new ApiError(401, "Unauthorized");
}
const issuer = context
.get("pluginConfig")
.providers.find((provider) => provider.id === issuerId);
@ -126,14 +114,6 @@ export default (plugin: PluginType): void => {
204: {
description: "Account unlinked",
},
401: {
description: "Unauthorized",
content: {
"application/json": {
schema: ErrorSchema,
},
},
},
404: {
description: "Account not found",
content: {
@ -148,10 +128,6 @@ export default (plugin: PluginType): void => {
const { id: issuerId } = context.req.valid("param");
const { user } = context.get("auth");
if (!user) {
throw new ApiError(401, "Unauthorized");
}
// Check if issuer exists
const issuer = context
.get("pluginConfig")

View file

@ -6,7 +6,6 @@ import {
generateRandomCodeVerifier,
} from "oauth4webapi";
import { z } from "zod";
import { ApiError } from "~/classes/errors/api-error.ts";
import { ErrorSchema } from "~/types/api";
import type { PluginType } from "../../index.ts";
import { oauthDiscoveryRequest, oauthRedirectUri } from "../../utils.ts";
@ -40,23 +39,11 @@ export default (plugin: PluginType): void => {
},
},
},
401: {
description: "Unauthorized",
content: {
"application/json": {
schema: ErrorSchema,
},
},
},
},
},
async (context) => {
const { user } = context.get("auth");
if (!user) {
throw new ApiError(401, "Unauthorized");
}
const linkedAccounts = await user.getLinkedOidcAccounts(
context.get("pluginConfig").providers,
);
@ -99,14 +86,6 @@ export default (plugin: PluginType): void => {
302: {
description: "Redirect to OpenID provider",
},
401: {
description: "Unauthorized",
content: {
"application/json": {
schema: ErrorSchema,
},
},
},
404: {
description: "Issuer not found",
content: {
@ -120,10 +99,6 @@ export default (plugin: PluginType): void => {
async (context) => {
const { user } = context.get("auth");
if (!user) {
throw new ApiError(401, "Unauthorized");
}
const { issuer: issuerId } = context.req.valid("json");
const issuer = context