Skip to content
Discussion options

You must be logged in to vote

So i just used jsonwebtoken plugin to verify if the jwt token is valid.

Here is the middleware:

'use strict'
const Env = use('Env')
const jwt = require('jsonwebtoken')

class SocketAuthentication {
  /**
  * @param {object} ctx
  * @param {Request} ctx.request
  * @param {Function} next
  */
  async wsHandle ({ request, auth }, next) {
    const { token } = request.all()
    const appKey = auth.authenticatorInstance._config.options.secret
    const jwtToken = token.split(' ')[1]
    jwt.verify(jwtToken, appKey)
    await next()
  }
}

module.exports = SocketAuthentication

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kempsteven
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant