Skip to content

Commit

Permalink
Made example code easier to read by duplicating Auth factory (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
reyesh authored and Jacob Wenger committed Jul 22, 2016
1 parent ab90729 commit 746edab
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions docs/guide/user-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ app.config(["$routeProvider", function($routeProvider) {
templateUrl: "views/home.html",
resolve: {
// controller will not be loaded until $waitForSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the example above
// Auth refers to our $firebaseAuth wrapper in the factory below
"currentAuth": ["Auth", function(Auth) {
// $waitForSignIn returns a promise so the resolve waits for it to complete
return Auth.$waitForSignIn();
Expand All @@ -319,7 +319,7 @@ app.config(["$routeProvider", function($routeProvider) {
templateUrl: "views/account.html",
resolve: {
// controller will not be loaded until $requireSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the example above
// Auth refers to our $firebaseAuth wrapper in the factory below
"currentAuth": ["Auth", function(Auth) {
// $requireSignIn returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
Expand All @@ -338,6 +338,12 @@ app.controller("AccountCtrl", ["currentAuth", function(currentAuth) {
// currentAuth (provided by resolve) will contain the
// authenticated user or null if not signed in
}]);

app.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
return $firebaseAuth();
}
]);
```

### `ui-router` Example
Expand All @@ -362,7 +368,7 @@ app.config(["$stateProvider", function ($stateProvider) {
templateUrl: "views/home.html",
resolve: {
// controller will not be loaded until $waitForSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the example above
// Auth refers to our $firebaseAuth wrapper in the factory below
"currentAuth": ["Auth", function(Auth) {
// $waitForSignIn returns a promise so the resolve waits for it to complete
return Auth.$waitForSignIn();
Expand All @@ -375,7 +381,7 @@ app.config(["$stateProvider", function ($stateProvider) {
templateUrl: "views/account.html",
resolve: {
// controller will not be loaded until $requireSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the example above
// Auth refers to our $firebaseAuth wrapper in the factory below
"currentAuth": ["Auth", function(Auth) {
// $requireSignIn returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
Expand All @@ -394,6 +400,12 @@ app.controller("AccountCtrl", ["currentAuth", function(currentAuth) {
// currentAuth (provided by resolve) will contain the
// authenticated user or null if not signed in
}]);

app.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
return $firebaseAuth();
}
]);
```
Keep in mind that, even when using `ng-annotate` or `grunt-ngmin` to minify code, that these tools
cannot peer inside of functions. So even though we don't need the array notation to declare our
Expand Down

0 comments on commit 746edab

Please sign in to comment.