Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Excalidraw Document with Authentication

User Signup or just password.

original excalidraw code

import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo?v=29";
import { blob } from "https://esm.town/v/std/blob?v=12";
import { createExcalidraw } from "https://jsr.io/@smallweb/excalidraw/0.3.0/mod.ts";
import { join } from "jsr:@std/path@0.225.2";

const { name } = extractValInfo(import.meta.url);
export default createExcalidraw({
  store: {
    get: async (key) => {
      try {
        const res = await blob.get(join(name, key));
        return new Uint8Array(await res.arrayBuffer());
      } catch (e) {
        return null;
      }
    },
    set: (key, value) => {
      return blob.set(join(name, key), value);
    },
  },
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This approach adds Lucia authentication with signup to the existing Excalidraw implementation.
// We'll use the luciaMiddleware to handle authentication and redirect unauthenticated users.
// The Excalidraw functionality will only be accessible to authenticated users.
import { html } from "https://esm.sh/common-tags@1.8.2";
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo?v=29";
import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth?v=84";
import { blob } from "https://esm.town/v/std/blob?v=12";
import { createExcalidraw } from "https://jsr.io/@smallweb/excalidraw/0.3.0/mod.ts";
import { join } from "jsr:@std/path@0.225.2";
const { name } = extractValInfo(import.meta.url);
const excalidrawHandler = createExcalidraw({
store: {
get: async (key) => {
try {
const res = await blob.get(join(name, key));
return new Uint8Array(await res.arrayBuffer());
} catch (e) {
return null;
}
},
set: (key, value) => {
return blob.set(join(name, key), value);
},
},
});
export default passwordAuth((req) => {
return excalidrawHandler(req);
}, { verifyPassword: (password) => password == "iamsecret" });
maxm-excalidrawpass.web.val.run
August 27, 2024