Creating a session

When using Cubed-Session, creating a session is really easy

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');

Cubed-Session will automaticly store the session ID. So you do not have to manually pass it in everytime you do something with your session.

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?