sub to newsletter on sign up

This commit is contained in:
keyan 2022-05-04 13:29:30 -05:00
parent 798b055fb9
commit 771978d562
4 changed files with 26 additions and 3 deletions

View File

@ -32,7 +32,9 @@ export default {
return null
}
await models.user.update({ where: { id: me.id }, data: { lastSeenAt: new Date() } })
models.user.update(
{ where: { id: me.id }, data: { lastSeenAt: new Date() } }
).catch(console.log)
return await models.user.findUnique({ where: { id: me.id } })
},

View File

@ -89,7 +89,7 @@ export default function Login ({ providers, callbackUrl, error, Header }) {
email: ''
}}
schema={EmailSchema}
onSubmit={({ email }) => {
onSubmit={async ({ email }) => {
signIn('email', { email, callbackUrl })
}}
>

View File

@ -28,6 +28,25 @@ const options = {
const { name } = await prisma.user.findUnique({ where: { id: token.id } })
token.name = name
}
// sign them up for the newsletter
if (isNewUser && profile.email) {
fetch(process.env.LIST_MONK_URL + '/api/subscribers', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + Buffer.from(process.env.LIST_MONK_AUTH).toString('base64')
},
body: JSON.stringify({
email: profile.email,
name: 'blank',
lists: [2],
status: 'enabled',
preconfirm_subscriptions: true
})
}).then(async r => console.log(await r.json())).catch(console.log)
}
return token
},
async session (session, token) {

View File

@ -1,6 +1,6 @@
import { Checkbox, Form, Input, SubmitButton } from '../components/form'
import * as Yup from 'yup'
import { Alert, InputGroup } from 'react-bootstrap'
import { Alert, Button, InputGroup } from 'react-bootstrap'
import { useMe } from '../components/me'
import LayoutCenter from '../components/layout-center'
import { useState } from 'react'
@ -85,6 +85,8 @@ export default function Settings () {
label='someone mentions me'
name='noteMentions'
/>
<div className='form-label'>saturday newsletter</div>
<Button href='https://mail.stacker.news/subscription/form' target='_blank'>(re)subscribe</Button>
<div className='d-flex'>
<SubmitButton variant='info' className='ml-auto mt-1 px-4'>save</SubmitButton>
</div>