mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): ♻️ Remove old redirect() and response() in favour of Hono's builtins
This commit is contained in:
parent
691716f7eb
commit
69d7d50239
20 changed files with 188 additions and 174 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue