import { Environment } from "relay-runtime" ; import { replaceAccessTokenOnTheFly } from "coral-framework/lib/auth" ; import { CoralContext } from "coral-framework/lib/bootstrap" ; import { createMutation } from "coral-framework/lib/relay" ; interface SetAccessTokenInput { /**
     * accessToken is the new access token to use for this session or persisted if
     * `ephemeral` is falsy.
     */ accessToken : string | null ; /**
     * ephemeral when set to true will ensure that the passed token is not
     * persisted to storage.
     */ ephemeral ? : boolean ; /**
     * refresh when set will not terminate the session but just replace the current access token.
     */ refresh ? : boolean ; } const SetAccessTokenMutation = createMutation ( "setAccessToken" , async ( environment , { accessToken , ephemeral , refresh } , { clearSession , subscriptionClient , localStorage } ) => { if ( refresh ) { if ( ! accessToken ) { console . error ( "Empty token given when trying to refresh access token" ) ; return ; } void replaceAccessTokenOnTheFly ( environment , subscriptionClient , localStorage , accessToken , { ephemeral , } ) ; return ; } await clearSession ( accessToken , { ephemeral } ) ; } ) ; export default SetAccessTokenMutation ;