Nitesh Kumar Nitesh Kumar - 1 month ago 6
AngularJS Question

how to set dynamic state based on forgot password email

I am sending below url to user for forgot-passwor:

http://myapp.client/home/#/reset-password/cykdufapPsD8LJCJBA1EC23C-C1BD-4411-1775-38577DF8FDF3I6U6TfKDXOfN11A1

How to get auth (string after /reset-password/) value and use that in state?

In my app.js file I want to have url of state to be dynamic and redirect user to reset-password page like below:

$stateProvider.state('reset-password', {
url: '/reset-password/:token',
templateUrl: '/home/login/views/prtl_resetPassword.html'
};
$urlRouterProvider.otherwise('/login');


When I load the page, I am redirected to login page. I can understand that token is not assigned which was sent to user eamil. What is the best solution for this?

Answer

The value from the URL fragment :token is used to populate $stateParams, which can be injected into a controller.

You can create a controller for the reset-password state. Inside the controller, you can take the token value from $stateParams and pass it on to the login state with $state.go().

Comments