Auth0 Home Blog Docs

Allow access to single page in app?

page
authentication
allow

#1

Hey guys,
My website is currently only accessible by login in through Auth0 but I want to make a single page accessible without authentication, a way for anyone to type in a specific URL and not have to log in. How can I do this?

Thanks


#2

You need to provide more information for anyone to be able to help you.

  • What type of app is it? SPA? Regular web app?
  • What framework/technologies is it using?
  • What Auth0 SDK’s are you using?

#3
  1. It’s an SPA
  2. I am using AngularJs
  3. Angular-JWT, auth0-lock

#4

Please refer to the Quickstart: https://auth0.com/docs/quickstart/spa/angularjs/04-authorization#protect-client-side-routes

To protect a route, you define a function to check authentication, then call this onEnter. To leave a route unprotected, simply don’t call this in the onEnter hook:

$stateProvider
  // ...
  .state('ping', {
    url: '/ping',
    controller: 'PingController',
    templateUrl: 'app/ping/ping.html',
    controllerAs: 'vm',
    onEnter: checkAuthentication // This protects the route. Simply don't call this to leave it unprotected.
  })

// ...

function checkAuthentication($transition$) {
  var $state = $transition$.router.stateService;
  var auth = $transition$.injector().get('authService');
  if (!auth.isAuthenticated()) {
    return $state.target('home');
  }
}

#5