Skip to content

Commit

Permalink
fix: #2274 ensure old-sessions do not persist (#2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcvay authored Aug 25, 2020
1 parent b9f3fc3 commit 274d012
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/connect-session/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
],
coverageThreshold: {
global: {
branches: 79,
branches: 78,
functions: 100,
lines: 100,
statements: 99
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-session/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reapit/connect-session",
"version": "2.0.1",
"version": "2.0.2",
"description": "OAuth Flow for Reapit Connect",
"keywords": [],
"homepage": "https://github.com/reapit/foundations#readme",
Expand Down
27 changes: 23 additions & 4 deletions packages/connect-session/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class ReapitConnectBrowserSession {
static TOKEN_EXPIRY = Math.round(new Date().getTime() / 1000) + 300 // 5 minutes from now
static GLOBAL_KEY = '__REAPIT_MARKETPLACE_GLOBALS__'
static REFRESH_TOKEN_KEY = 'REAPIT_REFRESH_TOKEN'
static USER_NAME_KEY = 'REAPIT_LAST_AUTH_USER'

// Private cached variables, I don't want users to reference these directly or it will get confusing.
// and cause bugs
Expand Down Expand Up @@ -57,21 +58,39 @@ export class ReapitConnectBrowserSession {
private get refreshToken(): string | null {
return (
this.session?.refreshToken ??
window.localStorage.getItem(`${ReapitConnectBrowserSession.REFRESH_TOKEN_KEY}_${this.connectClientId}`)
window.localStorage.getItem(
`${ReapitConnectBrowserSession.REFRESH_TOKEN_KEY}_${this.userName}_${this.connectClientId}`,
)
)
}

private get userName(): string | null {
return (
this.session?.loginIdentity.email ??
window.localStorage.getItem(`${ReapitConnectBrowserSession.USER_NAME_KEY}_${this.connectClientId}`)
)
}

private setRefreshToken(session: ReapitConnectSession) {
if (session.refreshToken) {
if (session.refreshToken && session.loginIdentity && session.loginIdentity.email) {
window.localStorage.setItem(
`${ReapitConnectBrowserSession.REFRESH_TOKEN_KEY}_${this.connectClientId}`,
`${ReapitConnectBrowserSession.REFRESH_TOKEN_KEY}_${session.loginIdentity.email}_${this.connectClientId}`,
session.refreshToken,
)
}
if (session.loginIdentity && session.loginIdentity.email) {
window.localStorage.setItem(
`${ReapitConnectBrowserSession.USER_NAME_KEY}_${this.connectClientId}`,
session.loginIdentity.email,
)
}
}

private clearRefreshToken() {
window.localStorage.removeItem(`${ReapitConnectBrowserSession.REFRESH_TOKEN_KEY}_${this.connectClientId}`)
window.localStorage.removeItem(
`${ReapitConnectBrowserSession.REFRESH_TOKEN_KEY}_${this.userName}_${this.connectClientId}`,
)
window.localStorage.removeItem(`${ReapitConnectBrowserSession.USER_NAME_KEY}_${this.connectClientId}`)
}

// See below, used to refresh session if I have a refresh token in local storage
Expand Down
14 changes: 0 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22550,13 +22550,6 @@ libnpmteam@^1.0.1:
get-stream "^4.0.0"
npm-registry-fetch "^4.0.0"

[email protected]:
version "3.1.1"
resolved "https://registry.yarnpkg.com/lie/-/lie-3.1.1.tgz#9a436b2cc7746ca59de7a41fa469b3efb76bd87e"
integrity sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=
dependencies:
immediate "~3.0.5"

lie@~3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/lie/-/lie-3.3.0.tgz#dcf82dee545f46074daf200c7c1c5a08e0f40f6a"
Expand Down Expand Up @@ -22817,13 +22810,6 @@ local-access@^1.0.1:
resolved "https://registry.yarnpkg.com/local-access/-/local-access-1.0.1.tgz#5121258146d64e869046c642ea4f1dd39ff942bb"
integrity sha512-ykt2pgN0aqIy6KQC1CqdWTWkmUwNgaOS6dcpHVjyBJONA+Xi7AtSB1vuxC/U/0tjIP3wcRudwQk1YYzUvzk2bA==

localforage@^1.7.3:
version "1.7.4"
resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.7.4.tgz#88b59cc9b25ae54c76bb2c080b21ec832c22d3f6"
integrity sha512-3EmVZatmNVeCo/t6Te7P06h2alGwbq8wXlSkcSXMvDE2/edPmsVqTPlzGnZaqwZZDBs6v+kxWpqjVsqsNJT8jA==
dependencies:
lie "3.1.1"

locate-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
Expand Down

0 comments on commit 274d012

Please sign in to comment.