Compare commits
2 Commits
91f30929da
...
e6baf7ab75
| Author | SHA1 | Date | |
|---|---|---|---|
|
e6baf7ab75
|
|||
|
cf24b34f63
|
28
src/index.ts
28
src/index.ts
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
textToArrayBuffer,
|
||||
arrayBufferToBase64Url,
|
||||
base64UrlToArrayBuffer,
|
||||
textToBase64Url,
|
||||
importKey,
|
||||
decodePayload
|
||||
textToArrayBuffer,
|
||||
arrayBufferToBase64Url,
|
||||
base64UrlToArrayBuffer,
|
||||
textToBase64Url,
|
||||
importKey,
|
||||
decodePayload
|
||||
} from "./utils"
|
||||
|
||||
if (typeof crypto === 'undefined' || !crypto.subtle)
|
||||
@@ -34,6 +34,13 @@ export type JwtHeader<T = {}> = {
|
||||
* @default "JWT"
|
||||
*/
|
||||
typ?: string
|
||||
|
||||
/**
|
||||
* Algorithm (default: `"HS256"`)
|
||||
*
|
||||
* @default "HS256"
|
||||
*/
|
||||
alg?: JwtAlgorithm
|
||||
} & T
|
||||
|
||||
/**
|
||||
@@ -196,7 +203,13 @@ export async function verify(token: string, secret: string | JsonWebKey | Crypto
|
||||
if (!algorithm)
|
||||
throw new Error('algorithm not found')
|
||||
|
||||
const { payload } = decode(token)
|
||||
const { header, payload } = decode(token)
|
||||
|
||||
if (header?.alg !== options.algorithm) {
|
||||
if (options.throwError)
|
||||
throw new Error('ALG_MISMATCH')
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
if (!payload)
|
||||
@@ -214,7 +227,6 @@ export async function verify(token: string, secret: string | JsonWebKey | Crypto
|
||||
} catch(err) {
|
||||
if (options.throwError)
|
||||
throw err
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
3
src/test.ts
Normal file
3
src/test.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { sign } from './index'
|
||||
|
||||
console.log(await sign())
|
||||
Reference in New Issue
Block a user