import { Context } from 'koa' ; import Shopify from '@shopify/shopify-api' ; import { Routes } from './types' ; import { AccessMode } from '../types' ; import { DEFAULT_ACCESS_MODE } from '../auth' ; export function redirectToAuth ( { fallbackRoute , authRoute } , ctx ) { const { query : { shop } , } = ctx ; const routeForRedirect = shop == null ? fallbackRoute : `${ authRoute }?shop=${ shop }` ; ctx . redirect ( routeForRedirect ) ; } export async function clearSession ( ctx , accessMode = DEFAULT_ACCESS_MODE ) { try { await Shopify . Utils . deleteCurrentSession ( ctx . req , ctx . res , accessMode === 'online' ) ; } catch ( error ) { if ( error instanceof Shopify . Errors . SessionNotFound ) { } else { throw error ; } } }