import querystring from 'querystring' ; import nonce from 'nonce' ; import type { NextApiRequest , NextApiResponse } from 'next' ; import { OAuthStartOptions } from '../types' ; import { setCookie } from "../helpers/cookies" ; const createNonce = nonce ( ) ; export default function oAuthQueryString ( req , res , options , callbackPath ) { const { scopes = [ ] , apiKey , accessMode , appUrl } = options ; const requestNonce = createNonce ( ) ; setCookie ( { res , name : 'shopifyNonce' , value : requestNonce . toString ( ) } ) ; const redirectParams = { state : requestNonce , scope : scopes . join ( ', ' ) , client_id : apiKey , redirect_uri : `${ appUrl }${ callbackPath }` , } ; if ( accessMode === 'online' ) { redirectParams [ 'grant_options[]' ] = 'per-user' ; } return querystring . stringify ( redirectParams ) ; }