Fork me on GitHub
#clojurescript
<
2021-12-07
>
ns02:12:51

Are there any tutorials on how to integrate Firebase (real time database) with Clojurescript on frontend? I'm using firebase js sdk 9.6.0, installed via npm, need to do auth and signInAnonymously - but I'm just really struggling with it all. I don't know if it has to do with version 9, obviously a few things might have changed, and all the tutorials I've found so far use versions below 9.

athomasoriginal18:12:07

Hey! Yeah, Firebase is an atypical NPM package. Are you using Figwheel-Main or Shadow?

ns21:12:31

Hi, I am using Shadow. I should say that I was able to get it going using version 7 (firebase js sdk) but version 9 I just couldn't get to work. I'm relatively new to clojurescript so it could be that I simply don't know what I am doing 🙂

jaju07:12:47

I’m also using firebase sdk v9 right now, and did struggle with cljs interop. I am not sure if my experience can be of any help, but please share any errors you’ve come across (and if possible, related code)

athomasoriginal14:12:09

@nedim version 9 is tricky even if you are experienced with Firebase. Let me dig up some pointers.

athomasoriginal14:12:14

If you want the figwheel way, I can also provide that, but I doubt you want to swap out tooling

ns15:12:43

@U6GNVEWQG I had not seen that, thank you so much! I'll give it a try and Shadow is just fine, like you said, prefer not to swap out tooling.

💯 1
athomasoriginal15:12:20

Totally. I wouldn’t suggest moving tooling. Just wanted to give you confidence that what you’re looking to do is achievable 🙂 Good luck!

ns15:12:03

Thank you! 🙂

Pepijn de Vos09:12:42

What would be a good way to fire an even when the user is "done typing"? IIRC closure library has stuff like rate limiting and delays but... not sure about this particular variant.

thheller09:12:08

"debounce" is probably what you want, as in goog.functions/debounce

kipz11:12:12

Good day! I'm after an opinion on which date/time library to use in a new cljs (node) project. I see there are a few out there. Just after doing basic is-after?/is-before? type stuff starting with js/Dates. Any thoughts?

p-himik11:12:37

Why not simply compare the dates? js/Date objects can be compared.

👍 1
David Vujic11:12:21

I have used date-fns and like the simplicity of it - when there is need to do something textual like “three days ago” 😄

👍 1
kipz11:12:22

oh cool! Been wanting that for ages 🙂

kipz11:12:42

Yeah - I think it makes sense to keep it simple for now. I can always add a library for fancier stuff later. I like the look of juxy/tick FWIW so far from my research.

David Vujic11:12:18

Oh, I guess I posted the wrong thing (wrong thread, Date, not Math) - trying to multi task posting + having lunch picard-facepalm 😆

kipz11:12:30

It's all good. Glad that maths library's on my radar now 🙂

Cora (she/her)12:12:49

luxon is the best js library I've used for dates, better than moment or date-fns or builtin

👍 1
emccue16:12:16

cljc java time is my pick

emccue16:12:40

maybe im the wierdo but im not sold on tick yet

dnolen16:12:58

@nedim latest Firebase doesn't currently work w/ plain ClojureScript, as Firebase structure changed (package.json "exports") and we need to address it - shadow-cljs I think probably works in this case

ns21:12:40

Hi, thank you for your response, I am using Shadow CLJS but still I couldn't get it to work. I am new to clojurescript so I wasn't sure if it's simply me not knowing what I'm doing, or if it's an issue with version 9 and compatibility with cljs. I ended up going back to version 7 (because I use that in production with regular javascript) and got it working.

henryw37408:12:12

Another option is not to include it in your build at all. Script tag in HTML

Akiz19:12:01

Hi, I am trying to PUT a file to Google Cloud Storage via cljs-http but I am getting Access to XMLHttpRequest at ... from origin '' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. I have got no problem when using CURL or Clojure HTTP Client. This is the cljs code:

(defn send-file [data presigned-url]
  (let [req {:request-method "PUT"
             :headers {"content-type" "application/octet-stream"}
             :body data
             :with-credentials? true}
        req-with-url (merge req (http/parse-url presigned-url))
        xhr (js/XMLHttpRequest.)]
    (http-core/xhr req-with-url)))

nenadalm20:12:44

cors error appears only when you make request from browser (not server), as it is browser who blocks the request in case server doesn't allow it via headers: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

👍 1
Akiz21:12:19

I know I just wanted to make sure that the same request is fine outside of the browser. But does it mean that Google does not allow me to upload the file from the browser?

nenadalm21:12:14

> But does it mean that Google does not allow me to upload the file from the browser? yes.

Akiz21:12:48

This does not seems to be CLJS problem - I must configure a bucket according to this. https://cloud.google.com/storage/docs/cross-origin

👍 1