You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can catch the rejected promise and redirect the unauthenticated user to a different page, such as the login page.
129
131
<br>
130
132
See the <ahref="/tutorial/step_08#authenticationwithrouters">“Authentication with Routers”</a> section of our tutorial for more information and a full example.
131
-
<br>
132
-
This method can receive a function as a parameter, which can be used to do custom validation prior to resolving/rejecting the promise.
133
-
<br>
134
-
If the validator function is present, the method will only resolve if the function returns true. If it returns a string, it will reject the promise with such string. Otherwise (false, null, undefined) it will reject the promise with the "FORBIDDEN" error string.
Resolves the promise successfully if a user is authenticated and the validatorFn returns true; rejects otherwise.
168
+
<br>
169
+
This is useful in cases where you want to require a route to have an authenticated user and do extra validation like the user's role or group.
170
+
<br>
171
+
You can catch the rejected promise and redirect the unauthenticated user to a different page, such as the login page.
172
+
<br>
173
+
See the <ahref="/tutorial/step_08#authenticationwithrouters">“Authentication with Routers”</a> section of our tutorial for more information and a full example.
174
+
<br>
175
+
The mandatory validator function will be called with the authenticated user as the single param and it's expected to return true in order to resolve. If it returns a string, the promise will be rejected using said string as the reason. Any other return (false, null, undefined) will be rejected with the default "FORBIDDEN" reason.
176
+
177
+
178
+
179
+
----
180
+
181
+
#### Example
182
+
183
+
// In route config ('ui-router' in the example, but works with 'ngRoute' the same way)
0 commit comments