florianheinemann / passwordless

node.js/express module to authenticate users without password
MIT License
1.95k stars 129 forks source link

Use without Express (microservice) #111

Closed NetOpWibby closed 6 years ago

NetOpWibby commented 6 years ago

I am trying to create an auth microservice that connects the marketing site with the app I am building. Currently, the example included in this repo requires Express to be used but I'm just using micro. So far I have the marketing site querying my microservice and looking up the user's info.

I'd love to have some input on how I could integrate Passwordless into my microservice but in the event I don't, I'll just come back here with my solution for future searchers. Once I went Passwordless, I couldn't go back.

EDIT: #66 seems close to my issue, hooray!

NetOpWibby commented 6 years ago

I am currently getting (node:4141) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 57): The "url" argument must be of type string. Received type undefined with the below code:

MongoStore.prototype.storeOrUpdate(token, userID, 3600000, domain, function (err) {
  if (err) log(`Error saving/updating TokenStore: ${err}`);
});

I have no idea why because domain IS a string. I'm pretty sure I'm matching what's in the passwordless-mongostore code here.

My token is generated via passwordless.Passwordless.prototype._generateToken()();, my userID is taken from my user._id.toString(), obviously 3600000 is milliseconds (an hour), and domain is http://localhost:3000. My URL argument would be domain right?

NetOpWibby commented 6 years ago

@florianheinemann Is there something obvious I'm missing here?

NetOpWibby commented 6 years ago

I figured out how to use jsonwebtoken, bcrypt, and other things to create my own passwordless system. The hardest part was figuring out how to save to a session.