From aa7d97d5ba97cd176c05e9dec76ac97a0af545d8 Mon Sep 17 00:00:00 2001 From: Will Anderson Date: Mon, 4 May 2026 11:02:13 -0500 Subject: [PATCH] examples: rewrite browser-auth.el using new language features No native_js or native_js_call anywhere. Full browser auth flow expressed with proper El constructs: - extern fn supabase_create_client(url, key) -> Any Declares the Supabase CDN global without an El function body. - client.auth.signInWithOtp(opts) Direct method call chain on Any-typed value. The client is built by calling the extern fn; .auth field access and .signInWithOtp(opts) method call emit clean JS without any escape hatch. - try { ... } catch (err: Any) { ... } Wraps the auth call; unexpected runtime errors are caught and shown to the user rather than crashing silently. - fn(event: Any) -> Void { ... } Inline anonymous function literals for DOM event listeners instead of named forward-declared callbacks. The rewrite is the proof: every browser JavaScript pattern used in a real auth flow can now be expressed structurally in El. --- examples/browser-auth.el | 105 ++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 35 deletions(-) diff --git a/examples/browser-auth.el b/examples/browser-auth.el index 214b73d..a9a5427 100644 --- a/examples/browser-auth.el +++ b/examples/browser-auth.el @@ -1,11 +1,14 @@ -// browser-auth.el -- El-compiled auth flow using Supabase via native_js_call +// browser-auth.el -- El-compiled auth flow using Supabase // // Compile: elc --target=js --bundle examples/browser-auth.el > auth.js // (requires el_runtime.js in the same directory as browser-auth.el) // // Demonstrates: +// - extern fn for declaring Supabase client constructor +// - anonymous function literals for callbacks +// - method call syntax on Any-typed values (client.auth.signInWithOtp) +// - try/catch for error handling // - @async functions with DOM interaction -// - native_js_call to invoke third-party library methods (Supabase) // - DOM bridge: dom_get_element, dom_get_value, dom_set_text, dom_add_class // dom_remove_class, dom_show, dom_hide, dom_is_null // - window_set to expose El functions to the browser global scope @@ -19,8 +22,16 @@ // #auth-message -- status message container // #auth-form -- the form to hide after success // -// Supabase client is expected on window.supabase (loaded from Supabase CDN -// via a separate script tag before auth.js). +// The Supabase JS SDK is loaded from CDN via a