feat(sso): implement SSO provider registration and update related components

- Refactored SSO registration logic in `register-oidc-dialog` and `register-saml-dialog` to use a new mutation method.
- Removed unused imports and error handling for registration failures.
- Added foreign key constraint for `organization_id` in the `sso_provider` table.
- Introduced new SSO schema and updated user relations to include SSO providers.
- Enhanced authentication flow to support SSO provider registration.
This commit is contained in:
Mauricio Siu
2026-01-31 04:43:47 -06:00
parent d22d96105c
commit d5de5b8ad7
11 changed files with 7348 additions and 50 deletions

View File

@@ -24,6 +24,7 @@ export const { handler, api } = betterAuth({
provider: "pg",
schema: schema,
}),
disabledPaths: ["/sso/register"],
appName: "Dokploy",
socialProviders: {
github: {
@@ -55,6 +56,7 @@ export const { handler, api } = betterAuth({
? [
"http://localhost:3000",
"https://absolutely-handy-falcon.ngrok-free.app",
"https://dev-pee8hhc3qbjlqedb.us.auth0.com",
]
: []),
];
@@ -113,7 +115,7 @@ export const { handler, api } = betterAuth({
}
} else {
const isSSORequest = context?.path.includes("/sso/callback");
if (isSSORequest) {
if (!isSSORequest) {
return;
}
const isAdminPresent = await db.query.member.findFirst({
@@ -184,9 +186,7 @@ export const { handler, api } = betterAuth({
isDefault: true, // Mark first organization as default
});
});
}
if (isSSORequest) {
} else if (isSSORequest) {
const providerId = context?.params?.providerId;
if (!providerId) {
throw new APIError("BAD_REQUEST", {
@@ -310,6 +310,7 @@ export const { handler, api } = betterAuth({
export const auth = {
handler,
createApiKey: api.createApiKey,
registerSSOProvider: api.registerSSOProvider,
};
export const validateRequest = async (request: IncomingMessage) => {