From 56ea1bc843484980be14d3a13df76cd5fe136fd3 Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Fri, 16 Jun 2023 15:57:33 +0100 Subject: [PATCH] feat(server): cleaned up boilerplate & using injected ref for consent tracking in fe register panel. --- packages/frontend-2/components/auth/RegisterPanel.vue | 4 ++++ .../frontend-2/components/auth/RegisterWithEmailBlock.vue | 6 ++++-- .../frontend-2/components/auth/third-party/LoginBlock.vue | 7 +++++-- packages/frontend-2/lib/auth/composables/auth.ts | 5 +---- packages/server/modules/auth/services/mailchimp.ts | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/frontend-2/components/auth/RegisterPanel.vue b/packages/frontend-2/components/auth/RegisterPanel.vue index e0831dcc5..d82dd5a22 100644 --- a/packages/frontend-2/components/auth/RegisterPanel.vue +++ b/packages/frontend-2/components/auth/RegisterPanel.vue @@ -63,6 +63,10 @@ graphql(` } `) +const newsletterConsent = ref(false) + +provide('newsletterconsent', newsletterConsent) + const { result } = useQuery(loginServerInfoQuery) const { appId, challenge, inviteToken } = useLoginOrRegisterUtils() diff --git a/packages/frontend-2/components/auth/RegisterWithEmailBlock.vue b/packages/frontend-2/components/auth/RegisterWithEmailBlock.vue index 3e2a8632d..54e68ba29 100644 --- a/packages/frontend-2/components/auth/RegisterWithEmailBlock.vue +++ b/packages/frontend-2/components/auth/RegisterWithEmailBlock.vue @@ -113,9 +113,11 @@ const password = ref('') const emailRules = [isEmail] const nameRules = [isRequired] -const { signUpWithEmail, inviteToken, newsletterConsent } = useAuthManager() +const { signUpWithEmail, inviteToken } = useAuthManager() const { triggerNotification } = useGlobalToast() +const newsletterConsent = inject>('newsletterconsent') + const pwdFocused = ref(false) const finalLoginRoute = computed(() => { @@ -134,7 +136,7 @@ const onSubmit = handleSubmit(async (fullUser) => { user, challenge: props.challenge, inviteToken: inviteToken.value, - newsletter: newsletterConsent.value + newsletter: newsletterConsent?.value }) } catch (e) { triggerNotification({ diff --git a/packages/frontend-2/components/auth/third-party/LoginBlock.vue b/packages/frontend-2/components/auth/third-party/LoginBlock.vue index 4e93a644c..927f951d9 100644 --- a/packages/frontend-2/components/auth/third-party/LoginBlock.vue +++ b/packages/frontend-2/components/auth/third-party/LoginBlock.vue @@ -48,7 +48,9 @@ const { public: { apiOrigin } } = useRuntimeConfig() const mixpanel = useMixpanel() -const { inviteToken, newsletterConsent } = useAuthManager() +const { inviteToken } = useAuthManager() + +const newsletterConsent = inject>('newsletterconsent') const NuxtLink = resolveComponent('NuxtLink') const GoogleButton = resolveComponent('AuthThirdPartyLoginButtonGoogle') @@ -68,10 +70,11 @@ const buildAuthUrl = (strat: StrategyType) => { url.searchParams.set('token', inviteToken.value) } - if (newsletterConsent.value) { + if (newsletterConsent?.value) { url.searchParams.set('newsletter', 'true') } + console.log(url) return url.toString() } diff --git a/packages/frontend-2/lib/auth/composables/auth.ts b/packages/frontend-2/lib/auth/composables/auth.ts index 0dd22e131..d19a9c530 100644 --- a/packages/frontend-2/lib/auth/composables/auth.ts +++ b/packages/frontend-2/lib/auth/composables/auth.ts @@ -282,16 +282,13 @@ export const useAuthManager = () => { goToLogin() } - const newsletterConsent = ref(false) - return { authToken, loginWithEmail, signUpWithEmail, logout, watchAuthQueryString, - inviteToken, - newsletterConsent + inviteToken } } diff --git a/packages/server/modules/auth/services/mailchimp.ts b/packages/server/modules/auth/services/mailchimp.ts index 77a7bd7d4..325b572ee 100644 --- a/packages/server/modules/auth/services/mailchimp.ts +++ b/packages/server/modules/auth/services/mailchimp.ts @@ -28,7 +28,7 @@ async function addToMailchimpAudience(userId: string) { // NOTE: using setListMember (NOT addListMember) to prevent errors for previously // registered members. - await mailchimp.lists.setListMember(config.listId + 'fail', subscriberHash, { + await mailchimp.lists.setListMember(config.listId, subscriberHash, { status_if_new: 'subscribed', email_address: user.email, merge_fields: {