import jwt, times, json, tables var secret = "secret" proc sign*(userId: string): string = var token = toJWT(%*{ "header": { "alg": "HS256", "typ": "JWT" }, "claims": { "userId": userId, "exp": (getTime() + 1.days).toSeconds().int } }) token.sign(secret) result = $token proc verify*(token: string): bool = try: let jwtToken = token.toJWT() result = jwtToken.verify(secret) except InvalidToken: result = false proc decode*(token: string): string = let jwt = token.toJWT() result = $jwt.claims["userId"].node.str var mytoken = sign("poop55") echo mytoken if mytoken.verify(): echo "Token verifyed, now decoding" echo "ID riped form token is: ", mytoken.decode() echo "Now go copy it to https://jwt.io/ and its invalid signature for some reson, tryed both base64 encoded and not " #FOR JWT I USED https://github.com/yglukhov/nim-jwt DUNO ANY ELSE :)