import Route from '@ember/routing/route';
import fetch from 'fetch';
import { serializeQueryParams } from 'ember-fetch/utils/serialize-query-params';
import window from 'ember-window-mock';

/**
 * This route will be called from the GitHub OAuth flow once the user has
 * accepted or rejected the data access permissions. It will forward the
 * temporary `code` received from the GitHub API to our own API server which
 * will exchange it for an access token.
 *
 * After the exchange the API will return an API token and the user information.
 * The result will be stored and the popup window closed. The `/login` route
 * will then continue to evaluate the response.
 *
 * @see https://developer.github.com/v3/oauth/#github-redirects-back-to-your-site
 * @see `/login` route
 */
export default Route.extend({
  async beforeModel(transition) {
    try {
      let queryParams = serializeQueryParams(transition.to.queryParams);
      let resp = await fetch(`/api/private/session/authorize?${queryParams}`);
      let json = await resp.json();
      let item = JSON.stringify({ ok: resp.ok, data: json });
      if (window.opener) {
        window.opener.github_response = item;
      }
    } catch (d) {
      let item = JSON.stringify({ ok: false, data: d });
      if (window.opener) {
        window.opener.github_response = item;
      }
    } finally {
      window.close();
    }
  },
});

@@ -66,89 +66,8 @@
 h';%0A
-import %7B serializeQueryParams %7D from 'ember-fetch/utils/serialize-query-params';%0A
 impo
@@ -781,43 +781,26 @@
 let 
-queryParams = serializeQueryParams(
+%7B code, state %7D = 
 tran
@@ -820,17 +820,16 @@
 ryParams
-)
 ;%0A      
@@ -887,21 +887,34 @@
 ize?
-$%7BqueryParams
+code=$%7Bcode%7D&state=$%7Bstate
 %7D%60);

Remove unnecessary `serializeQueryParams()` usage