Creating a session
When using Cubed-Session, creating a session is really easy
Before continuing: Cubed-Session requires you to enter your account details to login to the website. Make sure that when you are sharing your code, you do not share your account details.
When using Cubed-Session, we first need to require the package. We can do this by adding the following code at the top of our index file:
// Dependencies
const { Session } = require('cubed-session');Now we can create a new Session, there are settings you can explore in the documentation.
// Dependencies
const { Session } = require('cubed-session');
// Starting a new session
const session = new Session();Now we should log in to our account. We can also add an event to listen for the login. This will get fired when the session successfully logged in.
// Dependencies
const { Session } = require('cubed-session');
// Starting a new session
const session = new Session();
// Listening for the login event
session.on('login', (token) => console.log(`We logged in! Our session token is: ${token}`));
// Logging in
session.login('username', 'password');When we run our code now, we will see that in our console the following will show:
Congratulations! You now know how to log into your account;
Last updated
Was this helpful?