Skip to content

Commit 3a22127

Browse files
author
Giannis Katsanos
authored
fix(repo): Make vanillaJS playground work (clerk#3500)
1 parent 1183990 commit 3a22127

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

playground/vanillajs/index.html

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<script>
5-
// 👇 PUT YOUR API KEY HERE 👇
6-
window.__clerk_publishable_api = '';
7-
// 👆 PUT YOUR API KEY HERE 👆
8-
</script>
9-
<script src="../../packages/clerk-js/dist/clerk.browser.js"></script>
4+
<script
5+
async
6+
crossorigin="anonymous"
7+
data-clerk-publishable-key="<YOUR_PUBLISHABLE_KEY_GOES_HERE>"
8+
src="https://<YOUR_FRONTEND_API_URL_GOES_HERE>/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"
9+
type="text/javascript"
10+
></script>
1011
<style>
1112
body {
1213
font-family: sans-serif;
@@ -96,8 +97,8 @@ <h3>Clerk JS Playground</h3>
9697
<main>
9798
<p class="text">
9899
A simple playground for tinkering with vanilla js clerk and testing changes to components. To get started,
99-
create an application on Clerk and set your API key to the <code>window.__clerk_publishable_api</code> variable at
100-
the top of the source code.
100+
create an application on Clerk and set your API key to the <code>data-clerk-publishable-key</code> data attribute
101+
of the script that loads clerkJS.
101102
</p>
102103
<p>Use the buttons below to trigger basic functionality. Feel free to add more buttons as well!</p>
103104

@@ -113,6 +114,19 @@ <h3>Clerk JS Playground</h3>
113114
<div id="stage"></div>
114115

115116
<script>
117+
window.addEventListener("load", async function () {
118+
await Clerk.load();
119+
console.log("ClerkJS is loaded");
120+
121+
if (Clerk.user) {
122+
document.getElementById('username').innerText = Clerk.user.primaryEmailAddress.emailAddress;
123+
Clerk.mountUserButton(document.getElementById('userbutton'));
124+
}
125+
if (Clerk.organization) {
126+
Clerk.mountOrganizationSwitcher(document.getElementById('orgswitcher'));
127+
}
128+
});
129+
116130
const stage = document.getElementById('stage');
117131
// clerkjs functions return null when there's an error and use console.info for reporting
118132
// i recommend changing this, but for now we patch console.info to be able to display the err
@@ -148,17 +162,6 @@ <h3>Clerk JS Playground</h3>
148162
Clerk.mountOrganizationProfile(stage);
149163
}
150164

151-
// this does not appear to be working
152-
Clerk.load().then(() => {
153-
if (Clerk.user) {
154-
document.getElementById('username').innerText = Clerk.user.primaryEmailAddress.emailAddress;
155-
Clerk.mountUserButton(document.getElementById('userbutton'));
156-
}
157-
if (Clerk.organization) {
158-
Clerk.mountOrganizationSwitcher(document.getElementById('orgswitcher'));
159-
}
160-
});
161-
162165
// utility fn
163166
function el(tagName, content) {
164167
const tag = document.createElement(tagName);

0 commit comments

Comments
 (0)