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:
Now we can create a new Session, there are settings you can explore in the documentation.
// Dependenciesconst{Session}=require('cubed-session');// Starting a new sessionconstsession=newSession();
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.
// Dependenciesconst{Session}=require('cubed-session');// Starting a new sessionconstsession=newSession();// Listening for the login eventsession.on('login',(token)=>console.log(`We logged in! Our session token is: ${token}`));// Logging insession.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;