{"action":"created","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/693","repository_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project","labels_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/693/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/693/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/693/events","html_url":"https://github.com/ga-wdi-boston/capstone-project/issues/693","id":236299211,"number":693,"title":"[Ember] /palettes/create page is displayed even when not signed in","user":{"login":"nriser","id":16979795,"avatar_url":"https://avatars1.githubusercontent.com/u/16979795?v=3","gravatar_id":"","url":"https://api.github.com/users/nriser","html_url":"https://github.com/nriser","followers_url":"https://api.github.com/users/nriser/followers","following_url":"https://api.github.com/users/nriser/following{/other_user}","gists_url":"https://api.github.com/users/nriser/gists{/gist_id}","starred_url":"https://api.github.com/users/nriser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nriser/subscriptions","organizations_url":"https://api.github.com/users/nriser/orgs","repos_url":"https://api.github.com/users/nriser/repos","events_url":"https://api.github.com/users/nriser/events{/privacy}","received_events_url":"https://api.github.com/users/nriser/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-06-15T20:04:55Z","updated_at":"2017-06-15T20:46:40Z","closed_at":"2017-06-15T20:46:40Z","body":"I'm using the authentication files from our ember-auth lecture, and everything is working just fine. \r\n\r\nHere is my app so far: https://nriser.github.io/ember-capstone/#\r\n**(side question: Why does the deployed url have a '#' symbol?**\r\n\r\nWithout signing in, if you add ```/paletttes``` to the URL, you'll see that it gives you an error message (\"You must be signed in to access this page\") and get redirected to the sign-in page.\r\n(https://nriser.github.io/ember-capstone/#/palettes). \r\n\r\nHowever, if you type (https://nriser.github.io/ember-capstone/#/palettes/create), the palette-create-form and palette-analysis-form components in my palette-create route gets displayed. If you try to create a new palette, it'll give the below error:\r\n\r\nconsole error: \r\n```\r\nPOST https://colorpal.herokuapp.com//palettes 401 (Unauthorized)\r\n```\r\n\r\nEven though a user cannot create a new palette when not signed in, I want it so that it'll give an error message and redirect to the sign-in page like it does for the ```/palettes``` route. \r\n\r\nMy question is, why does the /palette page redirect to the sign-in page but not the /palette/create page? I can't seem to understand \r\n\r\nThis is what I currently have for templates/palette-create.hbs, the landing page, where the links to ```palette-create``` and ```palette``` routes are wrapped with {{#if isAuthenticated}}{{/if}}. \r\n\r\n```hbs\r\n<nav class=\"navbar navbar-default\">\r\n  <div class=\"container-fluid\">\r\n    {{navbar-header}}\r\n\r\n    <div class=\"collapse navbar-collapse\" id=\"navigation\">\r\n      <ul class=\"nav navbar-nav\">\r\n        {{#if isAuthenticated}}\r\n        {{!-- if user is authenticated, then display users --}}\r\n        <li>{{#link-to \"users\"}}Users{{/link-to}}</li>\r\n        {{/if}}\r\n      </ul>\r\n      <ul class=\"nav navbar-nav navbar-right\">\r\n        {{#if isAuthenticated}}\r\n        <li>{{#link-to \"change-password\"}}Change Password{{/link-to}}</li>\r\n        <li><a href=\"#\" {{action \"signOut\"}}>Sign Out</a></li>\r\n        {{else}}\r\n        <li>{{#link-to \"sign-up\"}}Sign Up{{/link-to}}</li>\r\n        <li>{{#link-to \"sign-in\"}}Sign In{{/link-to}}</li>\r\n        {{/if}}\r\n      </ul>\r\n    </div>\r\n  </div>\r\n</nav>\r\n\r\n<h1>Welcome to Ember!</h1>\r\n\r\n{{#each flashMessages.queue as |flash|}}\r\n  {{flash-message flash=flash}}\r\n{{/each}}\r\n\r\n{{#if isAuthenticated}}\r\n{{#link-to \"palette-create\"}}Create New Palette{{/link-to}}\r\n{{#link-to \"palettes\"}}My Palettes{{/link-to}}\r\n{{/if}}\r\n\r\n<div class=\"col-md-8 col-md-offset-2\">\r\n  {{outlet}}\r\n</div>\r\n```\r\n\r\n... but I think this simply displays/hides the ```palettes``` and ```palette-create``` links depending on whether you'er signed in or not.\r\n\r\nSo then I checked routes/application.js: \r\n```js\r\nimport Ember from 'ember';\r\n\r\nexport default Ember.Route.extend({\r\n  auth: Ember.inject.service(),\r\n  flashMessages: Ember.inject.service(),\r\n  actions: {\r\n    signOut () {\r\n      this.get('auth').signOut()\r\n        .then(() => this.get('store').unloadAll())\r\n        .then(() => this.transitionTo('sign-in'))\r\n        .then(() => {\r\n          this.get('flashMessages').warning('You have been signed out.');\r\n        })\r\n        .catch(() => {\r\n          this.get('flashMessages')\r\n          .danger('There was a problem. Are you sure you\\'re signed-in?');\r\n        });\r\n    },\r\n\r\n    error (reason) {\r\n      let unauthorized = reason.errors && reason.errors.some((error) =>\r\n        error.status === '401'\r\n      );\r\n\r\n      if (unauthorized) {\r\n        this.get('flashMessages')\r\n        .danger('You must be authenticated to access this page.');\r\n        this.transitionTo('/sign-in');\r\n      } else {\r\n        this.get('flashMessages')\r\n        .danger('There was a problem. Please try again.');\r\n      }\r\n\r\n      return false;\r\n    },\r\n  },\r\n});\r\n```\r\n\r\nI see that the redirecting is happening in the 'error' action, but I can't find where this action is being referenced anywhere else in the project repository. \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/comments/308861116","html_url":"https://github.com/ga-wdi-boston/capstone-project/issues/693#issuecomment-308861116","issue_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/693","id":308861116,"user":{"login":"nriser","id":16979795,"avatar_url":"https://avatars1.githubusercontent.com/u/16979795?v=3","gravatar_id":"","url":"https://api.github.com/users/nriser","html_url":"https://github.com/nriser","followers_url":"https://api.github.com/users/nriser/followers","following_url":"https://api.github.com/users/nriser/following{/other_user}","gists_url":"https://api.github.com/users/nriser/gists{/gist_id}","starred_url":"https://api.github.com/users/nriser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nriser/subscriptions","organizations_url":"https://api.github.com/users/nriser/orgs","repos_url":"https://api.github.com/users/nriser/repos","events_url":"https://api.github.com/users/nriser/events{/privacy}","received_events_url":"https://api.github.com/users/nriser/received_events","type":"User","site_admin":false},"created_at":"2017-06-15T20:46:40Z","updated_at":"2017-06-15T20:46:40Z","body":"Talked with @danman01 and came to a solution.\r\n\r\nThe solution (although Danny said it might not be the best solution) is to hit the backend API in the router model so that it triggers the ```error``` action in application.js (taken from the ember-auth class example). \r\n\r\nHere's an example router model:\r\n```js\r\n  model () {\r\n    let hitApiToRedirectToSignIn = this.get('store').findAll('palette');\r\n    return hitApiToRedirectToSignIn;\r\n  },\r\n```\r\n\r\nerror action in application.js\r\n```\r\nerror (reason) {\r\n      let unauthorized = reason.errors && reason.errors.some((error) =>\r\n        error.status === '401'\r\n      );\r\n\r\n      if (unauthorized) {\r\n        this.get('flashMessages')\r\n        .danger('You must be authenticated to access this page.');\r\n        this.transitionTo('/sign-in');\r\n      } else {\r\n        this.get('flashMessages')\r\n        .danger('There was a problem. Please try again.');\r\n      }\r\n```"}}
{"actor":{"display_login":"nriser"}}