mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(database): ♻️ Move Applications to our custom ORM
This commit is contained in:
parent
e8827bccfa
commit
9e96eca032
23 changed files with 424 additions and 381 deletions
|
|
@ -22,11 +22,11 @@ import {
|
|||
import { parse } from "qs";
|
||||
import type { z } from "zod";
|
||||
import { fromZodError } from "zod-validation-error";
|
||||
import type { Application } from "~/classes/functions/application";
|
||||
import { type AuthData, getFromHeader } from "~/classes/functions/user";
|
||||
import { db } from "~/drizzle/db";
|
||||
import { Challenges } from "~/drizzle/schema";
|
||||
import { config } from "~/packages/config-manager/index.ts";
|
||||
import { Application } from "~/packages/database-interface/application";
|
||||
import type { User } from "~/packages/database-interface/user";
|
||||
import type { ApiRouteMetadata, HonoEnv, HttpVerb } from "~/types/api";
|
||||
|
||||
|
|
@ -185,7 +185,9 @@ const checkRouteNeedsAuth = (
|
|||
return {
|
||||
user: auth.user as User,
|
||||
token: auth.token as string,
|
||||
application: auth.application as Application | null,
|
||||
application: auth.application
|
||||
? new Application(auth.application)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { Application } from "~/classes/functions/application";
|
||||
import type { Application } from "~/packages/database-interface/application";
|
||||
|
||||
/**
|
||||
* Check if an OAuth application is valid for a route
|
||||
|
|
@ -15,12 +15,12 @@ export const checkIfOauthIsValid = (
|
|||
}
|
||||
|
||||
const hasAllWriteScopes =
|
||||
application.scopes.split(" ").includes("write:*") ||
|
||||
application.scopes.split(" ").includes("write");
|
||||
application.data.scopes.split(" ").includes("write:*") ||
|
||||
application.data.scopes.split(" ").includes("write");
|
||||
|
||||
const hasAllReadScopes =
|
||||
application.scopes.split(" ").includes("read:*") ||
|
||||
application.scopes.split(" ").includes("read");
|
||||
application.data.scopes.split(" ").includes("read:*") ||
|
||||
application.data.scopes.split(" ").includes("read");
|
||||
|
||||
if (hasAllWriteScopes && hasAllReadScopes) {
|
||||
return true;
|
||||
|
|
@ -50,6 +50,6 @@ export const checkIfOauthIsValid = (
|
|||
|
||||
// If there are scopes left, check if they match
|
||||
return nonMatchedScopes.every((scope) =>
|
||||
application.scopes.split(" ").includes(scope),
|
||||
application.data.scopes.split(" ").includes(scope),
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue