https://supertokens.com/ logo
Docs
Join the conversationJoin Discord
Channels
community
contributing
general
github-activity
info
introductions
new-releases
random
security
support-questions
welcome-0xdelusion
welcome-aj-ya
welcome-aleksandrc
welcome-alpinjs
welcome-amberlamps1
welcome-andrew-rodriguez
welcome-ankit-choudhary
welcome-anthony-stod-custodio
welcome-call-in
welcome-chwalbox
welcome-claybiokiller
welcome-co7e
welcome-cosmoecwsa
welcome-devdag
welcome-dinso
welcome-drebotelho
welcome-elio
welcome-ernest
welcome-foxbarrington
welcome-fromscratch
welcome-galto4ir
welcome-goetzum
welcome-hay-kot
welcome-himanshu-kukreja
welcome-hossambarakat
welcome-ichikawakazuto
welcome-jahir9991
welcome-jamesl
welcome-jerry123424
welcome-john-oliver
welcome-jonas-alexanderson
welcome-jxyz
welcome-kelvinwop
welcome-kraz
welcome-lancekey
welcome-leoo
welcome-lukeacollins
welcome-m-j-mon
welcome-malik-khoja
welcome-marco
welcome-mardadi
welcome-meshguy
welcome-metamorph
welcome-mike-tectu
welcome-mirzok
welcome-mozomig
welcome-naberyou66_
welcome-nacer
welcome-namratha
welcome-naveenkumar
welcome-nightlight
welcome-nischith
welcome-notankit
welcome-olawumi
welcome-pavan-kumar-reddy-n
welcome-pineappaul
welcome-poothebear
welcome-rick
welcome-samuel-qosenergy
welcome-samuelstroschein
welcome-shubhamgoel23
welcome-shubhamkaushal
welcome-sidebar
welcome-surajsli
welcome-suyash_
welcome-syntaxerror
welcome-tauno
welcome-tauno
welcome-tawnoz
welcome-teclali
welcome-tls
welcome-turbosepp
welcome-vikram_shadow
welcome-yann
Powered by Linen
general
  • r

    rp

    07/15/2020, 4:13 PM
    not yet
  • l

    LucaCastelnuovo

    07/15/2020, 5:27 PM
    I currently have this POC code:
    js
    const express = require('express');
    const supertokens = require('supertokens-node');
    
    const app = express();
    const port = 3001;
    
    supertokens.init({
        hosts: 'https://try.supertokens.io',
        apiKey: 'key',
        cookieSecure: false,
        cookie_domain: 'localhost:3001',
    });
    
    //
    
    app.get('/', (req, res) => res.send('Hello World!'));
    
    app.get('/login', async (req, res) => {
        const userId = 'User1';
        const jwtPayload = { name: 'spooky action at a distance' };
        const sessionData = {
            awesomeThings: ['programming', 'javascript', 'supertokens'],
        };
    
        await supertokens.createNewSession(res, userId, jwtPayload, sessionData);
    
        res.send('logged in');
    });
    
    app.get('/refresh', supertokens.middleware(), (req, res) => {
        res.send('refresh done');
    });
    
    app.get('/dashboard', supertokens.middleware(), (req, res) => {
        const userId = req.session.getUserId();
    
        res.send(userId);
    });
    
    app.use('/logout', supertokens.middleware(), async (req, res) => {
        await req.session.revokeSession();
    
        res.send('loggoed out');
    });
    
    //
    
    app.use(
        supertokens.errorHandler({
            onUnauthorised: (err, req, res, next) => {
                // logging.logError(err); // some logging module
                res.status(440).send('Please login again');
            },
            onTryRefreshToken: (err, req, res, next) => {
                res.status(440).send('Call the refresh API');
            },
            onTokenTheftDetected: async (sessionHandle, userId, req, res, next) => {
                res.status(440).send('You are being attacked');
                await supertokens.revokeSession(sessionHandle);
            },
        }),
    );
    
    app.use((err, req, res, next) => {
        res.send(500).send(err);
    });
    
    app.listen(port, () => {
        console.log(`listening at http://localhost:${port}`);
    });
    If I visit http://localhost:3001/login no cookies get set. What did I do wrong?
  • r

    rp

    07/15/2020, 5:29 PM
    1) u don't need apiKey for try.supertokens.io 2) cookie_domain should only be localhost and then try again
  • l

    LucaCastelnuovo

    07/15/2020, 5:30 PM
    Nope, still doen't work
  • r

    rp

    07/15/2020, 5:30 PM
    in the response from that API, are you getting set-cookie headers?
  • l

    LucaCastelnuovo

    07/15/2020, 5:30 PM
    let me take a look
  • l

    LucaCastelnuovo

    07/15/2020, 5:31 PM
    Yes, but with an warning triangle, the warning says
  • l

    LucaCastelnuovo

    07/15/2020, 5:31 PM
    set cookie was blocked because of samesite being set on a non secure cookie
  • r

    rp

    07/15/2020, 5:32 PM
    was blocked or will be blocked in future versions?
  • l

    LucaCastelnuovo

    07/15/2020, 5:32 PM
    message has been deleted
  • r

    rp

    07/15/2020, 5:32 PM
    i see. then set sameSite: "lax" in the supertokens.init
  • l

    LucaCastelnuovo

    07/15/2020, 5:33 PM
    nope, same warning
  • r

    rp

    07/15/2020, 5:34 PM
    oops. it should be cookieSameSite
  • r

    rp

    07/15/2020, 5:34 PM
    and also, it shouldn't be cookie_domain, it should be cookieDomain
  • r

    rp

    07/15/2020, 5:34 PM
    See https://supertokens.io/docs/nodejs/api-reference/init
  • l

    LucaCastelnuovo

    07/15/2020, 5:34 PM
    great it works
  • l

    LucaCastelnuovo

    07/15/2020, 5:35 PM
    Thank you for the quick help
  • r

    rp

    07/15/2020, 5:35 PM
    ur welcome
  • l

    LucaCastelnuovo

    07/19/2020, 10:44 AM
    @User Would Lumen work with the Laravel version?
  • r

    rp

    07/19/2020, 12:35 PM
    I don't think so. That SDK was made specifically for Laravel and we haven't tried it with Lumen. You can try it out and if it works, then great!
  • r

    rp

    07/31/2020, 6:21 PM
    Hi @vdvn75
  • d

    Dee

    08/03/2020, 5:56 AM
    I have a very simple question, couldn't be more sillier maybe. What is the appropriate way for the UI to handle expiry of tokens. Should it be like the API is hit with an expired token, backend throws auth error and then UI hits another API to get refreshed tokens?
  • r

    rp

    08/03/2020, 6:00 AM
    that is one way.
  • r

    rp

    08/03/2020, 6:00 AM
    Another way is if the frontend knows that the token has expired already, and directly calls the refresh API
  • r

    rp

    08/03/2020, 6:01 AM
    how did you find out about us? Through our site or blog?
  • d

    Dee

    08/03/2020, 6:01 AM
    How does the frontend know the token has expired? By maintaining the expired_at or expired_in sort of a thing? Also a similar thing should be in place for refresh tokens?
  • d

    Dee

    08/03/2020, 6:02 AM
    And I knew about you guys recently just through searching for good articles on google for user authentication and came across the blog 😄
  • d

    Dee

    08/03/2020, 6:03 AM
    And ofcourse which one is preferred ?
  • r

    rp

    08/03/2020, 6:03 AM
    Yea.. store some value in localstorage or non-httpOnly cookie using which you can know when it expires. We can do that for the refresh token as well.. but that doesn't matter too much cause usage of refresh tokens is relatively rare anyway.
  • r

    rp

    08/03/2020, 6:03 AM
    I see. Are you looking to use supertokens? Or just curious?
Powered by Linen
Title
r

rp

08/03/2020, 6:03 AM
I see. Are you looking to use supertokens? Or just curious?
View count: 2