mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
* Add "authenticate" filter hook that allows custom auth check * Start on test * Update Jest, restructure API tests, start implementing authenticate test * Move access token verify to util function * Ensure jest can show inline warnings on correct lines * Update is-directus-jwt to use jsonwebtoken decode + add tests * Remove unused package * Tweak and finish + test authenticate * Tweak test * Add authenticate filter to docs * Don't scan tests for codeql * No seriously, ignore tests
16 lines
366 B
TypeScript
16 lines
366 B
TypeScript
import jwt from 'jsonwebtoken';
|
|
|
|
/**
|
|
* Check if a given string conforms to the structure of a JWT
|
|
* and whether it is issued by Directus.
|
|
*/
|
|
export default function isDirectusJWT(string: string): boolean {
|
|
try {
|
|
const payload = jwt.decode(string, { json: true });
|
|
if (payload?.iss !== 'directus') return false;
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|