src/docs/src/Perms/requestEmail.md
Request to see a user's email. If the user has already granted this permission the user will not be prompted and their email address will be returned. If the user grants permission their email address will be returned. If the user does not allow access undefined will be returned. If the user does not have an email address, the value of their email address will be null.
On a website, sign the user in to your site first with puter.auth.signIn(). This method reads the signed-in user's identity before it can prompt, so for a signed-out visitor it rejects with Unauthorized and no prompt is shown. Answering a permission prompt does not by itself sign the user in to your site, so guard the call:
if (!puter.authToken) await puter.auth.signIn();
puter.perms.requestEmail()
None
A Promise that resolves to:
string - The user's email address if permission is granted and the user has an emailnull - If permission is granted but the user does not have an email addressundefined - If permission is denied<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<button id="request-email">Request Email Access</button>
<script>
document.getElementById('request-email').addEventListener('click', async () => {
const email = await puter.perms.requestEmail();
if (email !== undefined) {
if (email === null) {
puter.print('User does not have an email address');
} else {
puter.print(`Email: ${email}`);
}
} else {
puter.print('Email access denied');
}
});
</script>
</body>
</html>