Handle missing Discord email sooner. Make sure emails are verified.

This commit is contained in:
Mihovil Ilakovac
2025-02-26 15:25:17 +01:00
parent dd334e28c6
commit 66d1155a0d
8 changed files with 112 additions and 64 deletions

View File

@@ -1,46 +1,64 @@
--- template/app/src/auth/userSignupFields.ts
+++ opensaas-sh/app/src/auth/userSignupFields.ts
@@ -1,11 +1,8 @@
@@ -1,8 +1,6 @@
import { z } from 'zod';
import { defineUserSignupFields } from 'wasp/auth/providers/types';
-const adminEmails = process.env.ADMIN_EMAILS?.split(',') || [];
-
export const getEmailUserFields = defineUserSignupFields({
username: (data: any) => data.email,
- isAdmin: (data: any) => adminEmails.includes(data.email),
email: (data: any) => data.email,
const emailDataSchema = z.object({
email: z.string(),
});
@@ -16,10 +14,6 @@
const emailData = emailDataSchema.parse(data);
return emailData.email;
},
- isAdmin: (data) => {
- const emailData = emailDataSchema.parse(data);
- return adminEmails.includes(emailData.email);
- },
});
@@ -29,10 +26,6 @@
const githubDataSchema = z.object({
@@ -45,14 +39,6 @@
const githubData = githubDataSchema.parse(data);
return githubData.profile.login;
},
- isAdmin: (data) => {
- const githubData = githubDataSchema.parse(data);
- return adminEmails.includes(githubData.profile.emails[0].email);
- const emailInfo = getGithubEmailInfo(githubData);
- if (!emailInfo.verified) {
- return false;
- }
- return adminEmails.includes(emailInfo.email);
- },
});
// NOTE: if we don't want to access users' emails, we can use scope ["user:read"]
@@ -58,10 +51,6 @@
// We are using the first email from the list of emails returned by GitHub.
@@ -85,13 +71,6 @@
const googleData = googleDataSchema.parse(data);
return googleData.profile.email;
},
- isAdmin: (data) => {
- const googleData = googleDataSchema.parse(data);
- if (!googleData.profile.email_verified) {
- return false;
- }
- return adminEmails.includes(googleData.profile.email);
- },
});
export function getGoogleAuthConfig() {
@@ -86,10 +75,6 @@
@@ -121,13 +100,6 @@
const discordData = discordDataSchema.parse(data);
return discordData.profile.username;
},
- isAdmin: (data) => {
- const email = discordDataSchema.parse(data).profile.email;
- return !!email && adminEmails.includes(email);
- const discordData = discordDataSchema.parse(data);
- if (!discordData.profile.email || !discordData.profile.verified) {
- return false;
- }
- return adminEmails.includes(discordData.profile.email);
- },
});

View File

@@ -8,16 +8,7 @@
interface PaymentPlanCard {
name: string;
@@ -82,7 +83,7 @@
}
if (!customerPortalUrl) {
- throw new Error(`Customer Portal does not exist for user ${user.id}`)
+ throw new Error(`Customer Portal does not exist for user ${user.id}`);
}
window.open(customerPortalUrl, '_blank');
@@ -96,11 +97,18 @@
@@ -105,16 +106,24 @@
Pick your <span className='text-yellow-500'>pricing</span>
</h2>
</div>
@@ -37,11 +28,17 @@
+ <span className='px-2 py-1 bg-gray-100 rounded-md text-gray-500'>4242 4242 4242 4242 4242</span>
+ </p>
+ </div>
+
{errorMessage && (
<div className='mt-8 p-4 bg-red-100 text-red-600 rounded-md dark:bg-red-200 dark:text-red-800'>
{errorMessage}
</div>
)}
+
<div className='isolate mx-auto mt-16 grid max-w-md grid-cols-1 gap-y-8 lg:gap-x-8 sm:mt-20 lg:mx-0 lg:max-w-none lg:grid-cols-3'>
{Object.values(PaymentPlanId).map((planId) => (
<div
@@ -187,7 +195,7 @@
@@ -201,7 +210,7 @@
)}
disabled={isPaymentLoading}
>