Note that there are some explanatory texts on larger screens.

plurals
  1. POEveryauth and accessing the (twitter) oauth data from within findUserById
    primarykey
    data
    text
    <p>I am trying to use <code>everyauth</code> within <code>express</code> to authenticate users to a website that allows adding text commentary to images. I am currently using the twitter oauth api to authenticate my users. </p> <p>Now I'm trying to established a custom user database that allows me to keep multiple ways of logging in connected to a single entry in a CouchDB. I am running into trouble when i want to add a new user to the DB when he initially connects via twitter. The code of my <code>findUserById</code> reads as following:</p> <pre><code>everyauth.everymodule.findUserById (userId, callback) -&gt; users.findById userId, (err,res) -&gt; if res.id # id returned, so there is an entry in the DB callback null, res else # no entry in the DB, add a new one users.saveById JSON.stringify(userId), {"name":"test"}, (saveErr, saveRes) -&gt; callback null, saveRes everyauth.twitter .consumerKey(config.twitterConsumerKey) .consumerSecret(config.twitterConsumerSecret) .findOrCreateUser((session, token, secret, user) -&gt; promise = @.Promise().fulfill user ).redirectPath '/' </code></pre> <p><code>findById</code> and <code>saveById</code> are methods of a <code>cradle</code> object that query the DB, <code>userId</code> is provided by everyauth, as it seems.</p> <p>My problem lies in the <code>{"name":"test"}</code> part. This is the location where I want to add the data from the <code>req.session.auth.twitter</code> object to the DB. <strong>How can I access those values from within the <code>findUserById</code>function?</strong></p> <p>Is that even possible? Is there a different approach? I am looking at the findOrCreateUser function, but I have no idea how to change that without crashing my app - i do not yet grasp the concept of the Promise.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload