How can i get "auth" object and verify my jwt token?


#1

Hey, i am switching from Adonis WS to Socket.io.
So there is no “auth” middleware or request object for me.
How can i get “auth” object and verify my jwt token?

This is my current socket.io code

'use strict';

const Server = use('Server');
const io = use('socket.io')(Server.getInstance());

io.use((socket, next) => {
	let token = socket.handshake.query.token;
	console.log('socket.io - token', token);
	return next();
});

io.on('connection', function(socket) {
	console.log('socket.io - connected', socket.id);
	socket.on('disconnect', reason => {
		console.log('socket.io - disconnected', socket.id, reason);
	});
});

#2

Hey,
You can wrap your socket.io instance as a middleware to acces to auth object.
https://adonisjs.com/docs/4.1/middleware

Or implement your own auth process using :
https://adonisjs.com/docs/4.1/authentication

take a look to :slight_smile:
https://stackoverflow.com/questions/36788831/authenticating-socket-io-connections