diff --git a/api/ssrApollo.js b/api/ssrApollo.js
index 2de50596..127a4edd 100644
--- a/api/ssrApollo.js
+++ b/api/ssrApollo.js
@@ -111,7 +111,7 @@ export function getGetServerSideProps (
}
if (error || !data || (notFound && notFound(data, vars, me))) {
- res.writeHead(301, {
+ res.writeHead(302, {
Location: '/404'
}).end()
}
diff --git a/components/invite.js b/components/invite.js
index 445175fb..766a65cd 100644
--- a/components/invite.js
+++ b/components/invite.js
@@ -21,7 +21,7 @@ export default function Invite ({ invite, active }) {
{invite.gift} sat gift
diff --git a/pages/api/auth/[...nextauth].js b/pages/api/auth/[...nextauth].js
index 342d60c8..42d30646 100644
--- a/pages/api/auth/[...nextauth].js
+++ b/pages/api/auth/[...nextauth].js
@@ -51,6 +51,17 @@ function getCallbacks (req) {
// token won't have an id on it for new logins, we add it
// note: token is what's kept in the jwt
token.id = Number(user.id)
+
+ // if referrer exists, set on user
+ // isNewUser doesn't work for nostr/lightning auth because we create the user before nextauth can
+ // this means users can update their referrer if they don't have one, which is fine
+ if (req.cookies.sn_referrer && user?.id) {
+ const referrer = await prisma.user.findUnique({ where: { name: req.cookies.sn_referrer } })
+ if (referrer) {
+ await prisma.user.updateMany({ where: { id: user.id, referrerId: null }, data: { referrerId: referrer.id } })
+ notifyReferral(referrer.id)
+ }
+ }
}
if (token?.id) {
@@ -60,33 +71,22 @@ function getCallbacks (req) {
token.sub = Number(token.id)
}
- if (isNewUser) {
- // if referrer exists, set on user
- if (req.cookies.sn_referrer && user?.id) {
- const referrer = await prisma.user.findUnique({ where: { name: req.cookies.sn_referrer } })
- if (referrer) {
- await prisma.user.update({ where: { id: user.id }, data: { referrerId: referrer.id } })
- notifyReferral(referrer.id)
- }
- }
-
- // sign them up for the newsletter
- if (user?.email && process.env.LIST_MONK_URL && process.env.LIST_MONK_AUTH) {
- 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: user.email,
- name: 'blank',
- lists: [2],
- status: 'enabled',
- preconfirm_subscriptions: true
- })
- }).then(async r => console.log(await r.json())).catch(console.log)
- }
+ // sign them up for the newsletter
+ if (isNewUser && user?.email && process.env.LIST_MONK_URL && process.env.LIST_MONK_AUTH) {
+ 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: user.email,
+ name: 'blank',
+ lists: [2],
+ status: 'enabled',
+ preconfirm_subscriptions: true
+ })
+ }).then(async r => console.log(await r.json())).catch(console.log)
}
return token
diff --git a/pages/invites/[id].js b/pages/invites/[id].js
index a138452f..e7516249 100644
--- a/pages/invites/[id].js
+++ b/pages/invites/[id].js
@@ -26,9 +26,10 @@ export async function getServerSideProps ({ req, res, query: { id, error = null
})
if (!data?.invite) {
- res.writeHead(301, {
+ res.writeHead(302, {
Location: '/404'
}).end()
+ return { props: {} }
}
if (session && res) {
@@ -36,19 +37,17 @@ export async function getServerSideProps ({ req, res, query: { id, error = null
// attempt to send gift
// catch any errors and just ignore them for now
await serialize(models,
- models.$queryRawUnsafe('SELECT invite_drain($1::INTEGER, $2::INTEGER)', session.user.id, id))
+ models.$queryRawUnsafe('SELECT invite_drain($1::INTEGER, $2::TEXT)', session.user.id, id))
const invite = await models.invite.findUnique({ where: { id } })
notifyInvite(invite.userId)
} catch (e) {
console.log(e)
}
- return {
- redirect: {
- destination: '/',
- permanent: false
- }
- }
+ res.writeHead(302, {
+ Location: '/'
+ }).end()
+ return { props: {} }
}
return {