Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18115 Login detection - proposed solution #1 #726

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/interfaces/state-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { NameCheckModelIF, StaffPaymentIF, RefundParamsIF } from '@/interfaces'

export interface StateModelIF {
common: {
currentJsDate: Date,
currentJsDate: Date
keycloakRoles: Array<string>
isAuthenticated: boolean
}
newRequestModel: NewRequestIF
staffPayment: StaffPaymentIF
Expand Down
5 changes: 3 additions & 2 deletions src/mixins/load-keycloak-roles-mixin.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Component, Vue } from 'vue-property-decorator'
import { getKeycloakRoles } from '@/plugins'
import { Action } from 'vuex-class'
import { ActionBindingIF } from '@/interfaces/store-interfaces'

@Component({})
export class LoadKeycloakRolesMixin extends Vue {
@Action setKeycloakRoles!: ActionBindingIF
@Action setKeycloakRoles!: (val: string[]) => void
@Action setIsAuthenticated!: (val: boolean) => void

/** Gets and stores Keycloak roles. */
loadKeycloakRoles (): void {
try {
const keycloakRoles = getKeycloakRoles()
this.setIsAuthenticated(keycloakRoles.length > 0)
this.setKeycloakRoles(keycloakRoles)
console.info('Got roles!') // eslint-disable-line no-console
} catch (err) {
Expand Down
5 changes: 4 additions & 1 deletion src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import querystring from 'qs'
import axios from 'axios'
import {
CompanyTypes,
EntityStates,
EntityTypes,
Location,
NameCheckAnalysisJurisdiction,
Expand Down Expand Up @@ -720,6 +719,10 @@ export const setRequestExaminationOrProvideConsent = ({ commit }, requestExamOrC
commit('mutateRequestExaminationOrProvideConsent', requestExamOrConsent)
}

export const setIsAuthenticated = ({ commit }, val: boolean): void => {
commit('mutateIsAuthenticated', val)
}

export const setKeycloakRoles = ({ commit }, keycloakRoles: string[]): void => {
commit('mutateKeycloakRoles', keycloakRoles)
}
Expand Down
12 changes: 5 additions & 7 deletions src/store/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
NameDesignationI,
NameRequestI,
RefundParamsIF,
RequestActionMappingI,
RequestActionsI,
RequestNameI,
RequestOrConsentIF,
Expand All @@ -38,7 +37,6 @@ import {
PriorityCode,
XproNameType
} from '@/enums'
import { SessionStorageKeys } from 'sbc-common-components/src/util/constants'

// List Data
// NB: can't use `this.$xxx` because we don't have `this` (ie, Vue)
Expand Down Expand Up @@ -66,11 +64,6 @@ export const isMobile = (state: StateIF): boolean => {
return (width < vuetifySm)
}

/** True if user is authenticated, else False. */
export const isAuthenticated = (): boolean => {
return Boolean(sessionStorage.getItem(SessionStorageKeys.KeyCloakToken))
}

export const getCurrentJsDate = (state: StateIF): Date => {
return state.stateModel.common.currentJsDate
}
Expand Down Expand Up @@ -1124,6 +1117,11 @@ export const getConditionalNameReservation = (state: StateIF): ConditionalReqI =
return data
}

/** Whether user is authenticated. */
export const isAuthenticated = (state: StateIF): boolean => {
return state.stateModel.common.isAuthenticated
}

/** The user's keycloak roles. */
export const getKeycloakRoles = (state: StateIF): Array<string> => {
return state.stateModel.common.keycloakRoles
Expand Down
4 changes: 4 additions & 0 deletions src/store/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ export const mutateUserCancelledAnalysis = (state: StateIF, userCancelledAnalysi
state.stateModel.newRequestModel.userCancelledAnalysis = userCancelledAnalysis
}

export const mutateIsAuthenticated = (state: StateIF, val: boolean) => {
state.stateModel.common.isAuthenticated = val
}

export const mutateKeycloakRoles = (state: StateIF, keyCloakRoles: Array<string>) => {
state.stateModel.common.keycloakRoles = keyCloakRoles
}
Expand Down
3 changes: 2 additions & 1 deletion src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
export const stateModel: StateModelIF = {
common: {
currentJsDate: null,
keycloakRoles: []
keycloakRoles: [],
isAuthenticated: false
},
newRequestModel: {
actingOnOwnBehalf: false,
Expand Down
Loading