refactor(api): ♻️ Remove old redirect() and response() in favour of Hono's builtins

This commit is contained in:
Jesse Wierzbinski 2024-08-28 17:01:56 +02:00
parent 691716f7eb
commit 69d7d50239
No known key found for this signature in database
20 changed files with 188 additions and 174 deletions

View file

@ -1,5 +1,5 @@
import { response } from "@/response";
import type { InferInsertModel } from "drizzle-orm";
import type { Context } from "hono";
import {
type AuthorizationServer,
authorizationCodeGrantRequest,
@ -146,6 +146,7 @@ export class OAuthManager {
async linkUser(
userId: string,
context: Context,
// Return value of automaticOidcFlow
oidcFlowData: Exclude<
Awaited<
@ -158,14 +159,14 @@ export class OAuthManager {
// Check if userId is equal to application.clientId
if (!flow.application?.clientId.startsWith(userId)) {
return response(null, 302, {
Location: `${config.http.base_url}${
return context.redirect(
`${config.http.base_url}${
config.frontend.routes.home
}?${new URLSearchParams({
oidc_account_linking_error: "Account linking error",
oidc_account_linking_error_message: `User ID does not match application client ID (${userId} != ${flow.application?.clientId})`,
})}`,
});
);
}
// Check if account is already linked
@ -178,27 +179,27 @@ export class OAuthManager {
});
if (account) {
return response(null, 302, {
Location: `${config.http.base_url}${
return context.redirect(
`${config.http.base_url}${
config.frontend.routes.home
}?${new URLSearchParams({
oidc_account_linking_error: "Account already linked",
oidc_account_linking_error_message:
"This account has already been linked to this OpenID Connect provider.",
})}`,
});
);
}
// Link the account
await this.linkUserInDatabase(userId, userInfo.sub);
return response(null, 302, {
Location: `${config.http.base_url}${
return context.redirect(
`${config.http.base_url}${
config.frontend.routes.home
}?${new URLSearchParams({
oidc_account_linked: "true",
})}`,
});
);
}
async automaticOidcFlow(