Skip to content

Commit

Permalink
fix: #2720 #2801 #2756 #2824 #2772 fixes various connect session bugs (
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcvay authored Oct 8, 2020
1 parent 330b4d3 commit da683ad
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions 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.6",
"version": "2.0.7",
"description": "OAuth Flow for Reapit Connect",
"keywords": [],
"homepage": "https://github.com/reapit/foundations#readme",
Expand All @@ -20,8 +20,8 @@
"main": "dist/index.js",
"umd:main": "dist/connect-session.umd.production.js",
"module": "dist/connect-session.esm.js",
"typings": "dist/connect-session/src/index.d.ts",
"types": "dist/connect-session/src/index.d.ts",
"typings": "dist/index.d.ts",
"types": "dist/index.d.ts",
"scripts": {
"build:prod": "cross-env NODE_ENV=production tsdx build --format=cjs,esm,umd",
"test:ci": "cross-env TZ=UTC jest --ci --colors --coverage --silent --forceExit --detectOpenHandles --runInBand",
Expand Down
7 changes: 4 additions & 3 deletions packages/connect-session/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { connectSessionVerifyDecodeIdToken } from '../utils/verify-decode-id-tok

export class ReapitConnectBrowserSession {
// Static constants
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'
Expand Down Expand Up @@ -108,8 +107,8 @@ export class ReapitConnectBrowserSession {
if (this.session) {
const decoded = jwt.decode(this.session.accessToken) as CoginitoAccess
const expiry = decoded['exp']

return expiry ? expiry < ReapitConnectBrowserSession.TOKEN_EXPIRY : true
const fiveMinsFromNow = Math.round(new Date().getTime() / 1000) + 300
return expiry ? expiry < fiveMinsFromNow : true
}

return true
Expand Down Expand Up @@ -164,6 +163,7 @@ export class ReapitConnectBrowserSession {
}

private handleError(error: string) {
this.clearRefreshToken()
console.error('Reapit Connect Error:', error)
}

Expand Down Expand Up @@ -202,6 +202,7 @@ export class ReapitConnectBrowserSession {
// Used as handler for login page button
public connectLoginRedirect(redirectUri?: string): void {
const loginRedirectUri = redirectUri || this.connectLoginRedirectPath
this.clearRefreshToken()
window.location.href = `${this.connectOAuthUrl}/login?response_type=code&client_id=${this.connectClientId}&redirect_uri=${loginRedirectUri}`
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/connect-session/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
exports[`Welcome should match snapshot 1`] = `
<Component
flexColumn={true}
isScrollable={true}
>
<Component
flexColumn={true}
hasPadding={true}
isScrollable={true}
>
<div
className=""
Expand All @@ -30,10 +31,11 @@ exports[`Welcome should match snapshot 1`] = `
exports[`Welcome should match snapshot for client 1`] = `
<Component
flexColumn={true}
isScrollable={true}
>
<Component
flexColumn={true}
hasPadding={true}
isScrollable={true}
>
<div
className=""
Expand All @@ -57,10 +59,11 @@ exports[`Welcome should match snapshot for client 1`] = `
exports[`Welcome should match snapshot for developer 1`] = `
<Component
flexColumn={true}
isScrollable={true}
>
<Component
flexColumn={true}
hasPadding={true}
isScrollable={true}
>
<div
className=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export const Welcome: React.FC<WelcomeProps> = () => {
const clientId = session?.connectSession?.loginIdentity?.clientId

return (
<FlexContainerBasic flexColumn isScrollable>
<FlexContainerResponsive flexColumn>
<FlexContainerBasic flexColumn>
<FlexContainerResponsive flexColumn isScrollable hasPadding>
<div className={logoWrapStyle}>
<img className={logoStyle} src={logo} alt="logo" />
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/reapit-connect/src/core/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const App = () => {

if (isUserWithDevIdOnly(session.connectSession?.loginIdentity)) {
window.location.href = window.reapit.config.developerPortalUrl
return null
}

return <Router />
Expand Down
2 changes: 1 addition & 1 deletion packages/reapit-connect/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit da683ad

Please sign in to comment.