import atob from 'atob' ; import logger from '../logger' ; /**
 * Check if a given string conforms to the structure of a JWT
 * and whether it is issued by Directus.
 */ export default function isDirectusJWT ( string ) { const parts = string . split ( '.' ) ; if ( parts . length !== 3 ) return false ; try { atob ( parts [ 0 ] ) ; atob ( parts [ 1 ] ) ; atob ( parts [ 2 ] ) ; } catch ( err ) { logger . error ( err ) ; return false ; } try { JSON . parse ( atob ( parts [ 0 ] ) ) ; const payload = JSON . parse ( atob ( parts [ 1 ] ) ) ; if ( payload . iss !== 'directus' ) return false ; } catch { return false ; } return true ; }