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

25067 Updated storage sync check #789

Merged
merged 1 commit into from
Jan 6, 2025
Merged
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
2 changes: 1 addition & 1 deletion app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ VUE_APP_LEGAL_API_URL="https://legal-api-dev.apps.silver.devops.gov.bc.ca"
VUE_APP_LEGAL_API_VERSION_2="/api/v2"
VUE_APP_NAMEX_API_URL="https://namex-dev.apps.silver.devops.gov.bc.ca"
VUE_APP_NAMEX_API_VERSION="/api/v1"
VUE_APP_STATUS_API_URL="https://status-api-dev.apps.silver.devops.gov.bc.ca"
VUE_APP_STATUS_API_URL="https://status-api-dev.apps.gold.devops.gov.bc.ca"
Copy link
Collaborator Author

@severinbeauvais severinbeauvais Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to developers: please update your .env file as needed.

VUE_APP_STATUS_API_VERSION="/api/v1"
VUE_APP_REGISTRIES_SEARCH_API_URL="https://bcregistry-dev.apigee.net/registry-search"
VUE_APP_REGISTRIES_SEARCH_API_VERSION="/api/v1"
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "name-request",
"version": "5.5.19",
"version": "5.5.20",
"private": true,
"appName": "Name Request UI",
"sbcName": "SBC Common Components",
Expand Down
2 changes: 1 addition & 1 deletion app/src/mixins/update-user-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class UpdateUserMixin extends Vue {
}
} catch (err) {
// just log the error -- no need to halt app
console.log('Launch Darkly update error =', err) // eslint-disable-line no-console
console.log('Error updating user =', err) // eslint-disable-line no-console
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error could be in fetchUserInfo or updateLaunchDarkly so I generalized this message.

}
}

Expand Down
32 changes: 15 additions & 17 deletions app/src/services/auth-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,22 @@ export default class AuthServices {
* Throws on error.
*/
static async fetchUserInfo (): Promise<any> {
// PREVENT_STORAGE_SYNC flag is set during signout in sbc common components
// when session is state cleared, as a mechanism to prevent returning async
// functions to set tokens
if (sessionStorage.getItem('PREVENT_STORAGE_SYNC')) return null
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
const url = `${this.authApiUrl}/users/@me`
// don't fetch user info if session isn't synced (ie, user is not logged in)
// to pre-empt a console error and Sentry log
if (sessionStorage.getItem('SESSION_SYNCED') !== 'true') return null
Copy link
Collaborator Author

@severinbeauvais severinbeauvais Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now checking a different session variable, same as in auth-web, ie.

image

I also left in the check for a KC token, but that's probably redundant. Or overly safe, you decide 😆


// don't fetch user info if there is no KC token (safety check)
const token = sessionStorage.getItem('KEYCLOAK_TOKEN')
if (token) {
const headers = {
Authorization: `Bearer ${token}`
}
return axios.get(url, { headers: headers })
.then(response => {
if (response?.data) return response.data
throw new Error('Invalid user info')
})
} else {
return null
}
if (!token) return null

const url = `${this.authApiUrl}/users/@me`
const headers = { Authorization: `Bearer ${token}` }

return axios.get(url, { headers: headers })
.then(response => {
if (response?.data) return response.data
throw new Error('Invalid user info')
})
}

/**
Expand Down
Loading