Commit db5e1aa2 authored by Tifenn Guillas's avatar Tifenn Guillas

Add comments for authentication module => DONE

parent b620de07
......@@ -27,4 +27,8 @@ import { AuthEffects } from './store/auth.effects';
initializeKeycloakAnis
]
})
/**
* @class
* @classdesc Authentication module.
*/
export class AuthModule { }
......@@ -11,36 +11,62 @@ import { Action } from '@ngrx/store';
import { UserProfile } from './user-profile.model';
export const LOGIN = '[Auth] Login';
export const LOGOUT = '[Auth] Logout';
export const AUTH_SUCCESS = '[Auth] Auth Success';
export const LOAD_USER_PROFILE_SUCCESS = '[Auth] Load User Profile Success';
export const OPEN_EDIT_PROFILE = '[Auth] Edit Profile';
/**
* @class
* @classdesc LoginAction action.
* @readonly
*/
export class LoginAction implements Action {
readonly type = LOGIN;
constructor(public payload: {} = null) { }
}
/**
* @class
* @classdesc LogoutAction action.
* @readonly
*/
export class LogoutAction implements Action {
readonly type = LOGOUT;
constructor(public payload: {} = null) { }
}
/**
* @class
* @classdesc AuthSuccessAction action.
* @readonly
*/
export class AuthSuccessAction implements Action {
readonly type = AUTH_SUCCESS;
constructor(public payload: {} = null) { }
}
/**
* @class
* @classdesc LoadUserProfileSuccessAction action.
* @readonly
*/
export class LoadUserProfileSuccessAction implements Action {
readonly type = LOAD_USER_PROFILE_SUCCESS;
constructor(public payload: UserProfile) { }
}
/**
* @class
* @classdesc OpenEditProfileAction action.
* @readonly
*/
export class OpenEditProfileAction implements Action {
readonly type = OPEN_EDIT_PROFILE;
......
......@@ -18,24 +18,37 @@ import * as authActions from './auth.action';
import { environment } from '../../../environments/environment';
@Injectable()
/**
* @class
* @classdesc Authentication effects.
*/
export class AuthEffects {
constructor(
private actions$: Actions,
private keycloak: KeycloakService
) { }
/**
* Logs in.
*/
@Effect({ dispatch: false })
loginAction$ = this.actions$.pipe(
ofType(authActions.LOGIN),
tap(_ => this.keycloak.login())
);
/**
* Logs out.
*/
@Effect({ dispatch: false })
logoutAction$ = this.actions$.pipe(
ofType(authActions.LOGOUT),
tap(_ => this.keycloak.logout())
);
/**
* Loads user profile when log in success.
*/
@Effect()
authSuccessAction$ = this.actions$.pipe(
ofType(authActions.AUTH_SUCCESS),
......@@ -46,6 +59,9 @@ export class AuthEffects {
)
);
/**
* Opens edit profile page.
*/
@Effect({ dispatch: false })
OpenEditProfileAction$ = this.actions$.pipe(
ofType(authActions.OPEN_EDIT_PROFILE),
......
......@@ -10,6 +10,11 @@
import * as actions from './auth.action';
import { UserProfile } from './user-profile.model';
/**
* Interface for authentication state.
*
* @interface State
*/
export interface State {
isAuthenticated: boolean;
userProfile: UserProfile;
......@@ -20,6 +25,14 @@ export const initialState: State = {
userProfile: null
};
/**
* Reduces state.
*
* @param {State} state - The state.
* @param {actions} action - The action.
*
* @return State
*/
export function reducer(state: State = initialState, action: actions.Actions): State {
switch (action.type) {
case actions.AUTH_SUCCESS:
......
......@@ -7,6 +7,11 @@
* file that was distributed with this source code.
*/
/**
* Interface for user profile.
*
* @interface UserProfile
*/
export interface UserProfile {
id?: string;
username?: string;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment