GithubHelp home page GithubHelp logo

Comments (10)

 avatar commented on May 20, 2024 1

It is working now, thank you sooo much ❤️

from hyper-express-session.

kartikk221 avatar kartikk221 commented on May 20, 2024

Yes, there is. You can store a boolean value like "logged_in" in your session and then check it on requests to determine if someone is logged in.

Simply put:
Start Session -> Check For Login Flag

from hyper-express-session.

 avatar commented on May 20, 2024

"Error: SessionEngine: Session was not started. Please call Request.session.start() before calling Request.session.get()"

Can I have an example?

from hyper-express-session.

kartikk221 avatar kartikk221 commented on May 20, 2024
webserver.post('/api/login', async (request, response) => {
    // Start the session
    await request.session.start();

    // Retrieve the flag or whatever property you use to specify if someone is logged in
    const is_logged_in = request.session.get('logged_in') === true;

   // Do stuff with is_logged_in
});

from hyper-express-session.

 avatar commented on May 20, 2024

How do I retrieve the "is_logged_in" value in other files?
Like express-session.

from hyper-express-session.

kartikk221 avatar kartikk221 commented on May 20, 2024

is_logged_in is not a property by default.

webserver.post('/api/login', async (request, response) => {
    // Assume you did validation and are ready to create their session, create it like below

    // Start the session
    await request.session.start();

   // Store session data (This is where you would store a flag / propery like is_logged_in)
   request.session.set({
        is_logged_in: true,
        account: 'something',
       something: 'something else'
    });

    // Send the response as you normally would
});

// Assume this is a authenticated endpoint
webserver.get('/api/account', async (request, response) => {
        // Start the session
        await request.session.start();

        // Retrieve the session data and check for is_logged_in property
        const session = request.session.get();
        if (session.is_logged_in) {
             // Do stuff here and return the account info and stuff
        }
});

from hyper-express-session.

 avatar commented on May 20, 2024

When you fetch at /api/account while your logged in, it will remove all the session data because it starts the session again, which resets the session.

Any way to get around that?

from hyper-express-session.

kartikk221 avatar kartikk221 commented on May 20, 2024

No, starting a session just means the underlying session object is initialized with data. It should not reset your session. If your session is begin reset every time you start it then that means you haven't properly configured the session engine to work with your storage mechanism properly.

Please see the examples on https://github.com/kartikk221/hyper-express-session/blob/main/docs/Examples.md for a better idea of how to integrate hyper-express-session

from hyper-express-session.

 avatar commented on May 20, 2024

Which Redis package are you using for https://github.com/kartikk221/hyper-express-session/blob/main/docs/Examples.md?

Cause the package I am using seems to have issues.

from hyper-express-session.

kartikk221 avatar kartikk221 commented on May 20, 2024

That example is based on https://github.com/luin/ioredis but the session engine should work with any database and any adapter as long as you properly reflect each of the engine's actions into your db

from hyper-express-session.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.