test: use better-auth built-in test plugin refactor: map auth errors server side refactor: native trusted providers callback usage <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Enhanced SSO authentication error messaging with specific guidance for different failure scenarios (account linking required, email verification needed, banned accounts, invite-only access). * **Chores** * Updated authentication dependencies to version 1.5.0. * **Tests** * Extended test coverage for SSO error code handling and authentication scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
31 lines
753 B
TypeScript
31 lines
753 B
TypeScript
import { db } from "~/server/db/db";
|
|
import { extractProviderIdFromUrl } from "../utils/sso-context";
|
|
|
|
export async function resolveTrustedProvidersForRequest(request?: Request): Promise<string[]> {
|
|
if (!request) {
|
|
return [];
|
|
}
|
|
|
|
const providerId = extractProviderIdFromUrl(request.url);
|
|
if (!providerId) {
|
|
return [];
|
|
}
|
|
|
|
const provider = await db.query.ssoProvider.findFirst({
|
|
columns: { organizationId: true },
|
|
where: { providerId },
|
|
});
|
|
if (!provider) {
|
|
return [];
|
|
}
|
|
|
|
const autoLinkingProviders = await db.query.ssoProvider.findMany({
|
|
columns: { providerId: true },
|
|
where: {
|
|
organizationId: provider.organizationId,
|
|
autoLinkMatchingEmails: true,
|
|
},
|
|
});
|
|
|
|
return autoLinkingProviders.map((entry) => entry.providerId);
|
|
}
|