Fork me on GitHub
#clojurescript
<
2022-11-12
>
Muhammad Hamza Chippa11:11:42

Hi all! Anyone have any experience working with the aws-cognito and using amazon-cognito-identity-js in reagent+re-frame application. I am trying to write signup handler in cljs but I am getting the Serialization error i.e. Start of structure or map found where not expected . Can any one help me in what I am doing wrong?

(def coginto-user-pool (new CognitoUserPool (clj->js {:region "xxxx"
                                                      :UserPoolId "xxx"
                                                      :ClientId "xxxx"})))

(defn sign-up-handler
  [email password]
  (. coginto-user-pool signUp
     email
     password
     [(new CognitoUserAttribute  {:Name "email" :Value email})]
     nil
     (fn [error data]
       (if error
         (do (js/console.log error)
             (error-notifier "Sign Up Failed"))
         (do
           (success-notifier "Verification email has been sent to your email address")
           (js/console.log "Sign Up Success" data))))))

p-himik11:11:46

(new CognitoUserAttribute ...) - are you use there isn't supposed to be a #js literal there, in front of the argument map? (a compile-time alternative for clj->js).

Muhammad Hamza Chippa11:11:46

I have tried to do it but still the same serialization error

p-himik11:11:40

The error surely has a stack trace. Have you tried following it in run time, seeing what data is in there?

Muhammad Hamza Chippa11:11:10

I am assuming I am sending the wrong arguments (but I have followed the documentation). Only error I am getting on submitting the form is the Serialization one

p-himik11:11:41

You can debug it right there in the browser, with the browser's built-in debugger.

p-himik11:11:19

You can break on requests to specific URLs, on exceptions, at specific places - all that is usually more than enough to debug such errors.

Muhammad Hamza Chippa11:11:44

Sure, let me try but I am assuming there is something with the arguments.

p-himik11:11:57

It very well might be. But more often than not it's much faster and much easier to debug it yourself rather than wait that someone with just the right knowledge comes by your question, has some back-and-forth with you, and figures out what's wrong. ;)

🙌 1
p-himik11:11:28

Also, that [(new ...)] should probably be #js [...] as well.

Brandon Stubbs15:11:11

(defn sign-up [email password]
  (let [user-pool  (AmazonCognitoIdentity/CognitoUserPool.
                     #js {:UserPoolId ""
                          :ClientId   ""})
        attributes #js [(AmazonCognitoIdentity/CognitoUserAttribute.
                          #js {:Name "email" :Value email})]]
    (.signUp user-pool email password attributes nil
      (fn [err result]
        (js/console.log err)
        (js/console.log result)))))