MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / getProviders

Function getProviders

packages/web/src/auth.ts:70–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

68}
69
70export const getProviders = async () => {
71 const hasSSOEntitlement = await hasEntitlement("sso");
72 const providers: IdentityProvider[] = [
73 ...(hasSSOEntitlement ? await getEEIdentityProviders() : []),
74 ];
75 const org = await __unsafePrisma.org.findUnique({ where: { id: SINGLE_TENANT_ORG_ID } });
76
77 const smtpConnectionUrl = getSMTPConnectionURL();
78 if (smtpConnectionUrl && env.EMAIL_FROM_ADDRESS && isEmailCodeLoginEnabled(org!)) {
79 providers.push({
80 __provider: EmailProvider({
81 server: smtpConnectionUrl,
82 from: env.EMAIL_FROM_ADDRESS,
83 maxAge: 60 * 10,
84 generateVerificationToken: async () => {
85 const token = String(Math.floor(100000 + Math.random() * 900000));
86 return token;
87 },
88 sendVerificationRequest: async ({ identifier, provider, token }) => {
89 const transport = createTransport(provider.server);
90 const html = await render(MagicLinkEmail({ token: token }));
91 const result = await transport.sendMail({
92 to: identifier,
93 from: provider.from,
94 subject: 'Log in to Sourcebot',
95 html,
96 text: `Log in to Sourcebot using this code: ${token}`
97 });
98
99 const failed = result.rejected.concat(result.pending).filter(Boolean);
100 if (failed.length) {
101 throw new Error(`Email(s) (${failed.join(", ")}) could not be sent`);
102 }
103 },
104 }),
105 type: "nodemailer",
106 id: "nodemailer",
107 purpose: "sso",
108 });
109 }
110
111 if (isCredentialsLoginEnabled(org!)) {
112 providers.push({
113 __provider: Credentials({
114 credentials: {
115 email: {},
116 password: {}
117 },
118 type: "credentials",
119 authorize: async (credentials) => {
120 const body = verifyCredentialsRequestSchema.safeParse(credentials);
121 if (!body.success) {
122 return null;
123 }
124 const { email, password } = body.data;
125
126 const user = await __unsafePrisma.user.findUnique({
127 where: { email }

Callers 7

setEmailCodeLoginEnabledFunction · 0.90
signInFunction · 0.85
auth.tsFile · 0.85

Calls 7

hasEntitlementFunction · 0.90
getEEIdentityProvidersFunction · 0.90
getSMTPConnectionURLFunction · 0.90
isEmailCodeLoginEnabledFunction · 0.90
onCreateUserFunction · 0.90
MagicLinkEmailFunction · 0.85

Tested by

no test coverage detected