Fork me on GitHub
#hyperfiddle
<
2024-01-07
>
mattias08:01:40

In https://github.com/hyperfiddle/electric-xtdb-starter/blob/master/src/user.clj we define user/!xtdb var, which works well for dev setups. In https://github.com/hyperfiddle/electric-starter-app/blob/main/src/prod.clj, you define prod as a separate namespace that just starts jetty. How would you handle a case when in prod we have a need to define such a stateful !xtdb var or e/def? In my project I have several such stateful objects/vars (for xtdb, graalvm context, playwright browser) which I initialise in user.clj and then later do (binding [!xtdb @(requiring-resolve 'user/!xtdb)]) . How should I approach this in uberjar deployments? Should I create some shared-vars namespace and (alter-var-root #'shared-vars/!xtdb) from both user.clj and prod.clj? Or alter-var-root does not work well with uberjars?

JAtkins21:01:57

Is there an easy way to boot electric in a server-only mode?

JAtkins00:01:41

Sweet! Yeah I’m interested in a POC - nothing solid is required :). Thanks!

Vincent23:01:07

I have re-thought my strategy for user phone number logins. Rather than write session data to the database, you can simply have the tuple/quadruple {:phone 777777777 :session "x2345" :expiry 99999999 :signature "signature-made-by-applying-algorithm-to-phone,sesh,expiry-with-your-secret-key-for-making-sigs"} and then the middleware can simply double check that the signature is valid for the given :phone, sesh, expiry ta.da.

Vincent00:01:01

one drawback being that manually expiring tokens will require some statefulness and that requires a db.

Vincent05:01:09

okay my latest and greatest strategy: do OTP validation in electric app set cookies in electric app via (set! (.-cookie js/document) (str name "=" value";")) immediately after, hit the server endpoint which confirms the sig is correct and if not, clears cookies. if good, returns cookies as they are. seems to be effective. time to shower xD