Comments (7)
Can you post a full reproduction script?
from jose.
Coding
import express, { Request, Response } from "express";
import { body } from "express-validator";
import { validateRequest, BadRequestError } from "sansction-common";
import jose from 'jose'
import { User } from "../models/user";
import { Password } from "../services/password";
const router = express.Router();
router.post(
"/api/users/signin",
[
body("email").isEmail().withMessage("Email must be valid"),
body("password")
.trim()
.notEmpty()
.isLength({ min: 4, max: 20 })
.withMessage("Password must be between 4 and 20 characters long"),
],
validateRequest,
async (req: Request, res: Response) => {
const { email, password } = req.body;
const user = await User.findOne({ email });
if (!user) {
throw new BadRequestError("Email not found", 404);
}
const passwordsMatch = await Password.compare(
user.password,
password
);
if (!passwordsMatch) {
throw new BadRequestError("Password not match", 401);
}
// Generate JWT
const secret = jose.base64url.decode(user.salt)
const userJWT = await new jose.EncryptJWT({ id: user.id, email: user.email })
.setExpirationTime('2h')
.encrypt(secret)
res.send({ 'accessToken': userJWT });
}
);
export { router as signinRouter };
Error msg
TypeError: Cannot read properties of undefined (reading 'base64url')
at D:\sanction-api\auth\src\routes\signin.ts:40:29
at Generator.next ()
at fulfilled (D:\sanction-api\auth\src\routes\signin.ts:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
from jose.
Please see the README on how to import the module.
In ESM you're supposed to
import * as jose from 'jose'
from jose.
Also, node version 16.20.1 is no longer supported on v5.x of jose, see CHANGELOG.md
from jose.
alright. thank you
from jose.
import * as jose from 'jose
Also, node version 16.20.1 is no longer supported on v5.x of jose, see CHANGELOG.md
I just tried in Node V16.20.1. So far looks good. I still need upgrade my node version?
from jose.
Yeah, Node.js v16.x is End-Of-Life since September 11th 2023.
from jose.
Related Issues (20)
- Check for `jwk.oth` should also check for `null` value HOT 2
- CryptoKey is not extractable HOT 1
- JWKS Timeout : request timed out HOT 1
- Claims validation should not mutate incoming `requiredClaims` array HOT 6
- jose importSPKI error TypeError: "spki" must be SPKI formatted string HOT 2
- Bun: Export named 'diffieHellman' not found in module 'crypto'. HOT 1
- Maybe slightly tweak the exports? HOT 4
- createLocalJWKSet should not generate a TS error when called with immutable input HOT 2
- Signature verification works in Node.js but fails in Cloudflare Workers HOT 1
- Cloudflare: The requested module 'node:crypto' does not provide an export named 'constants' HOT 5
- Support for AWS Lambda LLRT Runtime HOT 1
- `msw` is unable to intercept JWKS request in node environment due to namespace (`* as`) import HOT 1
- [Usage with Vitest/JSDOM] payload must be an instance of Uint8Array HOT 2
- Reference error: Key is not defined HOT 1
- JWT decryption does not support IVs longer than encryption key length for GCM HOT 9
- Minor error in example #112 HOT 1
- Signature validation fails when using mutliple JWKS endpoints HOT 8
- 5.6.0 normalizePrivateKey HOT 3
- HMAC key data must not be empty HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jose.