Skip to content

Commit

Permalink
Updated logout listener to take argument of the logged out user, chan…
Browse files Browse the repository at this point in the history
…ged the interface name to make more sense
  • Loading branch information
zakhenry committed Mar 8, 2016
1 parent 3a55cbe commit 91f948d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
8 changes: 4 additions & 4 deletions dist/ngJwtAuth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ declare module NgJwtAuth {
interface IUserFactory {
(subClaim: string, tokenData: IJwtClaims): ng.IPromise<IUser>;
}
interface ILoginListener {
(user: IUser): any;
interface IUserEventListener {
(user: IUser): void;
}
interface IBase64Service {
encode(string: string): string;
Expand Down Expand Up @@ -344,12 +344,12 @@ declare module NgJwtAuth {
* Register a login listener function
* @param loginListener
*/
registerLoginListener(loginListener: ILoginListener): void;
registerLoginListener(loginListener: IUserEventListener): void;
/**
* Register a logout listener function
* @param logoutListener
*/
registerLogoutListener(logoutListener: Function): void;
registerLogoutListener(logoutListener: IUserEventListener): void;
/**
* Get a user's token given their identifier
* @param userIdentifier
Expand Down
9 changes: 3 additions & 6 deletions dist/ngJwtAuth.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ngJwtAuth.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/ngJwtAuthInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ module NgJwtAuth {
(subClaim:string, tokenData:IJwtClaims): ng.IPromise<IUser>;
}

export interface ILoginListener {
(user:IUser):any;
export interface IUserEventListener {
(user:IUser):void;
}

export interface IBase64Service {
Expand Down
19 changes: 8 additions & 11 deletions src/ngJwtAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module NgJwtAuth {
//private properties
private userFactory:IUserFactory;
private loginPromptFactory:ILoginPromptFactory;
private loginListeners:ILoginListener[] = [];
private logoutListeners:Function[] = [];
private loginListeners:IUserEventListener[] = [];
private logoutListeners:IUserEventListener[] = [];
private userLoggedInPromise:ng.IPromise<any>;

private refreshTimerPromise:ng.IPromise<any>;
Expand Down Expand Up @@ -514,9 +514,7 @@ module NgJwtAuth {
*/
private handleLogin(user:IUser):void {

_.each(this.loginListeners, (listener:ILoginListener) => {
listener(user);
});
_.invoke(this.loginListeners, _.call, null, user);

}

Expand Down Expand Up @@ -661,27 +659,26 @@ module NgJwtAuth {
public logout():void {
this.clearJWTToken();
this.loggedIn = false;
this.user = null;

_.each(this.logoutListeners, (listener:Function) => {
listener();
});
//call all logout listeners with user that is logged out
_.invoke(this.logoutListeners, _.call, null, this.user);
this.user = null;
}


/**
* Register a login listener function
* @param loginListener
*/
public registerLoginListener(loginListener:ILoginListener):void {
public registerLoginListener(loginListener:IUserEventListener):void {
this.loginListeners.push(loginListener);
}

/**
* Register a logout listener function
* @param logoutListener
*/
public registerLogoutListener(logoutListener:Function):void {
public registerLogoutListener(logoutListener:IUserEventListener):void {
this.logoutListeners.push(logoutListener);
}

Expand Down

0 comments on commit 91f948d

Please sign in to comment.