W
Wasp4d ago
fred-123

Is there a way to track if a user actually clicked the email verification link

Many of my users forget to click the link and it gets tideous asking them all if they did it or not. Is there a way to track in the server console or somewhere else if they actuall clicked it so its easiert to check?
3 Replies
kapa.ai
kapa.ai4d ago
Hi @fred-123. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, there is a way to track if a user has clicked the email verification link in Wasp. This information is stored in the user's data and can be accessed programmatically. Here's how you can implement and check this: 1. Email Verification Status: When using email authentication in Wasp, the user's email verification status is automatically tracked. This is stored in the isEmailVerified field of the user's provider data. 2. Checking Verification Status: You can check the email verification status in your server-side code. Here's an example of how you might do this in a custom sign-up action:
const providerData = deserializeAndSanitizeProviderData(existingAuthIdentity.providerData)
if (providerData.isEmailVerified) {
// User has clicked the verification link
} else {
// User has not yet clicked the verification link
}
const providerData = deserializeAndSanitizeProviderData(existingAuthIdentity.providerData)
if (providerData.isEmailVerified) {
// User has clicked the verification link
} else {
// User has not yet clicked the verification link
}
3. Logging: You can add logging statements in your server-side code to track when a user verifies their email. This would appear in your server console. 4. Custom Tracking: If you want more detailed tracking, you could implement a custom solution. For example, you could add a field to your User entity to store the verification date, and update this when the user verifies their email. 5. Email Verification Flow: Wasp provides a built-in email verification flow. When a user clicks the verification link, Wasp automatically updates their verification status. For more detailed information on implementing and customizing email verification in Wasp, you can refer to these resources: Email Authentication Auth Entities Remember, it's important to respect user privacy and only collect and store necessary information. Always inform users about what data you're collecting and why. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @fred-123, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Vinny (@Wasp)
Vinny (@Wasp)4d ago
@miho can you maybe suggest a good way to present this data to the app admin?
miho
miho4d ago
I'd advise you to check https://wasp.sh/docs/auth/entities to understand the auth entities structure and then you can do something like this:
import {
createProviderId,
findAuthIdentity,
updateAuthIdentityProviderData,
getProviderData,
} from 'wasp/server/auth';

const providerId = createProviderId('email', args.email)
const authIdentity = await findAuthIdentity(providerId)
if (!authIdentity) {
throw new HttpError(400, "Unknown user")
}

const providerData = getProviderData<'email'>(authIdentity.providerData)
// providerData will have `isEmailVerified`
import {
createProviderId,
findAuthIdentity,
updateAuthIdentityProviderData,
getProviderData,
} from 'wasp/server/auth';

const providerId = createProviderId('email', args.email)
const authIdentity = await findAuthIdentity(providerId)
if (!authIdentity) {
throw new HttpError(400, "Unknown user")
}

const providerData = getProviderData<'email'>(authIdentity.providerData)
// providerData will have `isEmailVerified`
Accessing User Data | Wasp
First, we'll check out the most practical info: how to access the user's data in your app.

Did you find this page helpful?