simpleddp-plugin-login (SimpleDDP Meteor.Accounts Login Plugin)
This is plugin for simpleDDP js library. Use it to authenticate with any Meteor.Accounts login provider (also custom).
Version 4.0.2
Plugin is for simpleDDP
>= 2.2.4
For previous versions see.
Install
npm install simpleddp-plugin-login --save
Usage
Extends simpleDDP
instance.
const simpleDDP = ;const simpleDDPLogin = simpleDDPLogin; let opts = endpoint: "ws://someserver.com/websocket" SocketConstructor: WebSocket reconnectInterval: 5000;const server = optssimpleDDPLogin;
Adds events (login
, logout
, loginResume
, loginSessionLost
, loginResumeFailed
),methods (login
, logout
) and userId
property
which is undefined
when user is not logged in or is equal to user._id when user is logged in.
Also token
property when user is logged in.
Plugin automatically resumes authentication if connection with server was lost and then restored back.
simpleDDP.login(auth)
Call this method to login with any Meteor.Accounts login provider.
Returns
A Promise which resolves to the object with userId of the logged in user when the login succeeds, or rejects when it fails.
Example for Accounts Password
serveruserId; // undefined, we are not logged in let password = "somepassword";let username = "admin";let email = "admin@admin"; // you must pass password and at least one of username or emaillet userAuth = await server; // userAuth will be something like this// { id: 'd6PqCAKk2QZeqZHWy',// token: 'N50Gmknk__geP63YD9pHKdl07b8XXxNGpB_cz5Lte4d',// tokenExpires: { '$date': 1548525528846 },// type: 'password' } serveruserId; // now equals to 'd6PqCAKk2QZeqZHWy'servertoken; // now equals to 'N50Gmknk__geP63YD9pHKdl07b8XXxNGpB_cz5Lte4d'
simpleDDP.logout()
Call this method to logout.
Returns
A Promise which resolves to undefined when the logout succeeds, or rejects when it fails.
Example
await server;
Events Example
server; server; server