내 서비스에서 유저에 대한 검증이 필요한 케이스는 상황에 따라 다양하겠지만, 대표적으로 “내 서비스의 백엔드 API 서버에서 내 서비스 유저에게만 API 호출을 허용하고 싶을 때”를 생각해볼 수 있습니다.
백엔드 API 서버에서는 API를 호출한 주체가 내 서비스의 유저인지 아닌지를 어떻게 알 수 있을까요?
const jwt = require('jsonwebtoken');// Your secret key (keep this secret!)const secretKey = 'your-secret-key';// An example JWT to verifyconst token = 'your-jwt-token-here';try { // Verify the JWT const decoded = jwt.verify(token, secretKey); // If verification succeeds, 'decoded' will contain the payload data console.log('JWT Verified successfully'); console.log('Decoded JWT payload:', decoded);} catch (error) { // If verification fails, an error will be thrown console.error('JWT verification failed:', error.message);}