Skip to content

Commit 60d3bb2

Browse files
committed
feat(client:auth): add types to async functions, update documentation
1 parent aa2741d commit 60d3bb2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Diff for: templates/app/client/components/auth(auth)/auth.service.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
3232
* Authenticate user and save token
3333
*
3434
* @param {Object} user - login info
35-
* @param {Function} callback - optional, function(error, user)
35+
* @param {Function} callback - function(error, user)
3636
* @return {Promise}
3737
*/
38-
login({email, password}, callback: Function) {
38+
login({email, password}, callback?: Function) {
3939
return $http.post('/auth/local', { email, password })
4040
.then(res => {
4141
$cookies.put('token', res.data.token);
@@ -65,10 +65,10 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
6565
* Create a new user
6666
*
6767
* @param {Object} user - user info
68-
* @param {Function} callback - optional, function(error, user)
68+
* @param {Function} callback - function(error, user)
6969
* @return {Promise}
7070
*/
71-
createUser(user, callback) {
71+
createUser(user, callback?: Function) {
7272
return User.save(user,
7373
function(data) {
7474
$cookies.put('token', data.token);
@@ -86,10 +86,10 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
8686
*
8787
* @param {String} oldPassword
8888
* @param {String} newPassword
89-
* @param {Function} callback - optional, function(error, user)
89+
* @param {Function} callback - function(error, user)
9090
* @return {Promise}
9191
*/
92-
changePassword(oldPassword, newPassword, callback) {
92+
changePassword(oldPassword, newPassword, callback?: Function) {
9393
return User.changePassword({ id: currentUser._id }, { oldPassword, newPassword }, function() {
9494
return safeCb(callback)(null);
9595
}, function(err) {
@@ -100,10 +100,10 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
100100
/**
101101
* Gets all available info on a user
102102
*
103-
* @param {Function} [callback] - optional, function(user)
103+
* @param {Function} [callback] - function(user)
104104
* @return {Promise}
105105
*/
106-
getCurrentUser(callback) {
106+
getCurrentUser(callback?: Function) {
107107
var value = currentUser.hasOwnProperty('$promise')
108108
? currentUser.$promise
109109
: currentUser;
@@ -131,9 +131,9 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
131131
* Check if a user is logged in
132132
*
133133
* @param {Function} [callback] - function(is)
134-
* @return {Bool|Promise}
134+
* @return {Promise}
135135
*/
136-
isLoggedIn(callback) {
136+
isLoggedIn(callback?: Function) {
137137
return Auth.getCurrentUser(undefined)
138138
.then(user => {
139139
var is = user.hasOwnProperty('role');
@@ -156,9 +156,9 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
156156
*
157157
* @param {String} role - the role to check against
158158
* @param {Function} [callback] - function(has)
159-
* @return {Bool|Promise}
159+
* @return {Promise}
160160
*/
161-
hasRole(role, callback) {
161+
hasRole(role, callback?: Function) {
162162
return Auth.getCurrentUser(undefined)
163163
.then(user => {
164164
var has = user.hasOwnProperty('role')

0 commit comments

Comments
 (0)