Skip to content

Commit 9b46bce

Browse files
committed
add puter sign-in
1 parent 5e4d79a commit 9b46bce

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const fastify = Fastify({
2929
serverFactory: (handler) => {
3030
return createServer()
3131
.on("request", (req, res) => {
32-
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
33-
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
32+
// res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
33+
// res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
3434

3535
if (bare.shouldRoute(req)) {
3636
bare.routeRequest(req, res);

static/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
href="https://fonts.googleapis.com/css2?family=Hind:wght@300;400;500;600;700&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
2424
rel="stylesheet"
2525
/>
26+
<script src="https://js.puter.com/v2/"></script>
2627
<style>
2728
body,
2829
html,

static/ui.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,59 @@ const col = css`
2929

3030
connection.setTransport(store.transport, [{ wisp: store.wispurl }]);
3131

32+
let signedinr;
33+
let signedin = new Promise((resolve) => (signedinr = resolve));
34+
35+
function SignIn() {
36+
this.css = `
37+
transition: opacity 0.4s ease;
38+
:modal[open] {
39+
animation: fade 0.4s ease normal;
40+
}
41+
42+
:modal::backdrop {
43+
backdrop-filter: blur(3px);
44+
}
45+
`;
46+
this.status = "";
47+
48+
function handleModalClose(modal) {
49+
modal.style.opacity = 0;
50+
setTimeout(() => {
51+
modal.close();
52+
modal.style.opacity = 1;
53+
}, 250);
54+
}
55+
56+
const signin = async () => {
57+
this.status = "Signing in...";
58+
console.log("??");
59+
try {
60+
await puter.auth.signIn();
61+
this.status = "Signed in successfully!";
62+
signedinr();
63+
handleModalClose(this.root);
64+
} catch (e) {
65+
console.log(e);
66+
this.status = "Error signing in: " + e.message;
67+
return;
68+
}
69+
};
70+
71+
return html`
72+
<dialog
73+
class="signin"
74+
style="background-color: #121212; color: white; border-radius: 8px;"
75+
>
76+
<h1>Sign In</h1>
77+
<p>Sign in with Puter to accses Scramjet Browser</p>
78+
79+
<button on:click=${signin}>Sign In</button>
80+
<p>${use(this.status)}</p>
81+
</dialog>
82+
`;
83+
}
84+
3285
function Config() {
3386
this.css = `
3487
transition: opacity 0.4s ease;
@@ -197,6 +250,18 @@ function BrowserApp() {
197250

198251
const frame = scramjet.createFrame();
199252

253+
this.mount = async () => {
254+
if (!puter.auth.isSignedIn()) {
255+
const signin = h(SignIn);
256+
document.body.appendChild(signin);
257+
signin.showModal();
258+
await signedin;
259+
}
260+
261+
let wisp = await puter.net.generateWispV1URL();
262+
console.log(wisp);
263+
};
264+
200265
frame.addEventListener("urlchange", (e) => {
201266
if (!e.url) return;
202267
this.url = e.url;
@@ -225,7 +290,7 @@ function BrowserApp() {
225290
<button on:click=${() => frame.forward()}>-&gt;</button>
226291
<button on:click=${() => frame.reload()}>&#x21bb;</button>
227292
228-
<input class="bar" autocomplete="off" autocapitalize="off" autocorrect="off"
293+
<input class="bar" autocomplete="off" autocapitalize="off" autocorrect="off"
229294
bind:value=${use(this.url)} on:input=${(e) => {
230295
this.url = e.target.value;
231296
}} on:keyup=${(e) => e.keyCode == 13 && (store.url = this.url) && handleSubmit()}></input>

0 commit comments

Comments
 (0)