User sessions — Create a Connect 4 online training

Now that we have gone through the front-end part, we will be able to attack the server part, starting with the user session system. For the server we will use Fastify and we will manage sessions stateless without using a database.

When the user contacts the server, he will be assigned a unique identifier and a signature that will be created using a private key. To manage this cryptography part we will rely on the NodeJS crypto API

import Fastify from 'fastify'
import { v4 } from 'uuid'
import { sign } from './func/crypto'

const fastify = Fastify({logger: true})'/api/players', (req, res) => {
  const playerId = v4() // On génère un id unique à la volée
  const signature = sign(playerId)
    id: playerId,
    signature: signature

fastify.listen({port: 8000}).catch((err) => {
}).then(() => {'Le serveur écoute sur le port 8000')


Please enter your comment!
Please enter your name here