Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7660387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:27:32+00:00 2026-05-31T13:27:32+00:00

I am trying to use everyauth within express to authenticate users to a website

  • 0

I am trying to use everyauth within express 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.

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 findUserById reads as following:

everyauth.everymodule.findUserById (userId, callback) ->  
    users.findById userId, (err,res) ->
        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) ->
                callback null, saveRes

everyauth.twitter
    .consumerKey(config.twitterConsumerKey)
    .consumerSecret(config.twitterConsumerSecret)
    .findOrCreateUser((session, token, secret, user) ->
         promise = @.Promise().fulfill user
    ).redirectPath '/'

findById and saveById are methods of a cradle object that query the DB, userId is provided by everyauth, as it seems.

My problem lies in the {"name":"test"} part. This is the location where I want to add the data from the req.session.auth.twitter object to the DB. How can I access those values from within the findUserByIdfunction?

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:27:32+00:00Added an answer on May 31, 2026 at 1:27 pm

    After fiddling around further, I have found a solution to the problem i posed. To access the full user data that is transmitted with the OAuth request with respect to the Promise-structure of everyauth, the everyauth.twitter call should look like this:

    everyauth.twitter
     .consumerKey(config.twitterConsumerKey)
     .consumerSecret(config.twitterConsumerSecret)
     .findOrCreateUser((session, token, secret, user) ->
       users.findByTwitterId user.id, (err,res) ->
         if res.id
           user=res.value
         else
           newUser = {id:user.id,name:user.name,twitter:user}
           user = newUser
           users.saveById JSON.stringify(user.id), user, (saveErr, saveRes) -> 
       promise = @.Promise().fulfill user
     ).redirectPath '/'
    

    The findByTwitterId call is a function that queries the CouchDB for a view looking up documents that contain a twitter.id field.

    The req.user object is populated by this:

    everyauth.everymodule.findUserById (userId, callback) ->  
     users.findByTwitterId userId, (err,res) ->
        if res.id
            callback null, res.value
        else
            callback null, null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying use eco for client-side templating. I have multiple .eco templates that I'd
I have a regex that I'm trying use to validate against strings. Trying to
I have a 3rd party DLL that I am trying to use in a
I'm working with VS2010 express on Win7 (64 bit) and I'm trying use System.ServiceModel
I am trying use the jQuery table sorter plugin for a table that is
I am trying use the mysql connector in c++ in ubuntu. It appears that
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying use a Java Uploader in a ROR app (for its ease

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.