mirror of
https://github.com/siv-org/siv.git
synced 2026-01-10 19:07:57 -05:00
Fix /submitted's reminder to validate email for link-auth
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { firebase } from 'api/_services'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const { election_id } = req.query as { election_id: string }
|
||||
const { link_auth } = req.body
|
||||
|
||||
const electionDoc = firebase.firestore().collection('elections').doc(election_id)
|
||||
const vote = await electionDoc.collection('votes-pending').doc(link_auth).get()
|
||||
|
||||
// Is there a vote w/ this link_auth token?
|
||||
if (!vote.exists) return res.status(200).send('Unverified')
|
||||
|
||||
// Has it verified?
|
||||
if (vote.data()?.is_email_verified) return res.status(200).send('Verified')
|
||||
|
||||
// Must still be pending application
|
||||
return res.status(200).send('Unverified')
|
||||
}
|
||||
@@ -5,20 +5,29 @@ import { api } from 'src/api-helper'
|
||||
export const UnverifiedEmailModal = () => {
|
||||
const [isModalOpen, setModalOpen] = useState(false)
|
||||
const [email, setEmail] = useState('')
|
||||
const { auth, election_id } = useRouter().query as { auth?: string; election_id?: string }
|
||||
const { auth, election_id, link_auth } = useRouter().query as {
|
||||
auth?: string
|
||||
election_id?: string
|
||||
link_auth?: string
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
async function getVerificationStatus() {
|
||||
const response = await api(`election/${election_id}/get-application-status`, { auth })
|
||||
const request = link_auth
|
||||
? api(`election/${election_id}/get-link-auth-verification-status`, { link_auth })
|
||||
: api(`election/${election_id}/get-application-status`, { auth })
|
||||
|
||||
const response = await request
|
||||
|
||||
// No voter found or already pre-approved
|
||||
if (response.status >= 400) return
|
||||
|
||||
const status = await response.text()
|
||||
|
||||
// Show warning if unverified
|
||||
if (status == 'Unverified') {
|
||||
setModalOpen(true)
|
||||
setEmail(localStorage.getItem(`registration-${auth}`) || 'your email')
|
||||
setEmail(localStorage.getItem(`registration-${link_auth || auth}`) || 'your email')
|
||||
}
|
||||
}
|
||||
getVerificationStatus()
|
||||
|
||||
Reference in New Issue
Block a user