Skip to content

Commit

Permalink
Add both verified and unverified flows
Browse files Browse the repository at this point in the history
  • Loading branch information
verschoren committed Feb 14, 2024
1 parent a388211 commit 6e8a90c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
21 changes: 17 additions & 4 deletions docs/messaging.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@ <h2 class="text-xl font-medium text-blue-gray-900">User Info</h2>
</div>
</div>
<div class="flex justify-end gap-3">
<button onclick="Login('email')" id="login" type="button" class="relative inline-flex items-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-10">
<button onclick="Login('email_verified')" id="login" type="button" class="relative inline-flex items-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-10">
<svg class="-ml-0.5 h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path d="M3 4a2 2 0 0 0-2 2v1.161l8.441 4.221a1.25 1.25 0 0 0 1.118 0L19 7.162V6a2 2 0 0 0-2-2H3Z" />
<path d="m19 8.839-7.77 3.885a2.75 2.75 0 0 1-2.46 0L1 8.839V14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8.839Z" />
</svg>
Login with email
Login with verified email
</button>
<button onclick="Login('email_unverified')" id="login" type="button" class="relative inline-flex items-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-10">
<svg class="-ml-0.5 h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path d="M3 4a2 2 0 0 0-2 2v1.161l8.441 4.221a1.25 1.25 0 0 0 1.118 0L19 7.162V6a2 2 0 0 0-2-2H3Z" />
<path d="m19 8.839-7.77 3.885a2.75 2.75 0 0 1-2.46 0L1 8.839V14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8.839Z" />
</svg>
Login with unverified email
</button>
<button type="button" onclick="Login('external_id')" id="login" class="relative -ml-px gap-x-1.5 inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-10">
<svg class="-ml-0.5 h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
Expand Down Expand Up @@ -207,8 +214,14 @@ <h1 class="text-sm font-medium pb-2">Subscribe to Internal Note</h1>

//replace with your worker URLs
url = 'https://jwtauth.internalnote.com/messaging';
if (type == 'email'){
url = 'https://jwtauth.internalnote.com/messaging_email';
if (type == 'external_id'){
url = 'https://jwtauth.internalnote.com/messaging';
}
if (type == 'email_verified'){
url = 'https://jwtauth.internalnote.com/messaging_email_verified';
}
if (type == 'email_unverified'){
url = 'https://jwtauth.internalnote.com/messaging_email_unverified';
}

//get token for current user
Expand Down
45 changes: 29 additions & 16 deletions messaging-worker/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ export default {
var response_messaging = await respondMessaging(json,env,"external_id");
response_messaging.headers.set("access-control-allow-origin", "*");
return response_messaging;
case "/messaging_email":
var response_messaging = await respondMessaging(json,env,"email");
case "/messaging_email_verified":
var response_messaging = await respondMessaging(json,env,"email_verified");
response_messaging.headers.set("access-control-allow-origin", "*");
return response_messaging;
case "/messaging_email_unverified":
var response_messaging = await respondMessaging(json,env,"email_unverified");
response_messaging.headers.set("access-control-allow-origin", "*");
return response_messaging;
default :
Expand Down Expand Up @@ -50,21 +54,30 @@ async function respondMessaging(json,env,type) {

var payload;
if (type == "external_id") {
payload = JSON.stringify({
scope: "user",
name: json.user_name,
email: json.user_email,
external_id: "user_" + json.user_email,
exp: Math.floor(new Date().getTime() / 1000.0) + 86400,
});
payload = JSON.stringify({
scope: "user",
name: json.user_name,
email: json.user_email,
external_id: "user_" + json.user_email,
exp: Math.floor(new Date().getTime() / 1000.0) + 86400,
});
} else if (type == "email_verified") {
payload = JSON.stringify({
scope: "user",
name: json.user_name,
email: json.user_email,
exp: Math.floor(new Date().getTime() / 1000.0) + 86400,
external_id: "user_" + json.user_email,
email_verified: true
});
} else {
payload = JSON.stringify({
scope: "user",
name: json.user_name,
email: json.user_email,
exp: Math.floor(new Date().getTime() / 1000.0) + 86400,
email_verified: true
});
payload = JSON.stringify({
scope: "user",
name: json.user_name,
email: json.user_email,
exp: Math.floor(new Date().getTime() / 1000.0) + 86400,
external_id: "user_" + json.user_email,
});
}

const partialToken = `${base64URLStringify(
Expand Down

0 comments on commit 6e8a90c

Please sign in to comment.