D
D
dfhkjhg2020-11-22 11:10:48
JavaScript
dfhkjhg, 2020-11-22 11:10:48

Do I need to use serializeUser and deserializeUser when authorizing via passport-steam + jwt?

const SteamStrategy = new Strategy({
    returnURL: 'http://localhost:5000/auth/steam/return',
    realm: 'http://localhost:5000/',
    apiKey: 'key'
}, (identifier, { id }, done) => done(null, id))

router.get('/steam/return', passport.authenticate('steam'), ({ user }, res) => {
    //чек юзера
    const token = createToken(user)
    console.log(token)
    res.cookie('jwt', token).redirect('http://localhost:8080/')
})

router.get('/is-logged', async (req, res) => {
    const json = { user: null }
    const token = req?.cookies?.jwt 
    const steamid = checkToken(token)

    if (!token || !steamid) return res.status(200).json(json)

    json.user = await getUser({ steamid })
    
    return res.status(200).json(json)
})


this is how the authorization-related code looks like after the jwt strategy is created
and should it be used in this case:

passport.serializeUser((user, done) =>  done(null, user))
passport.deserializeUser((obj, done) => done(null, obj))

app.use(passport.session())

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question