Skip to content

Commit

Permalink
fix ssr support
Browse files Browse the repository at this point in the history
  • Loading branch information
salvoravida committed Jun 10, 2019
1 parent a42110b commit cdadbdf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ const MyProtectedPage = withAdalLoginApi(MyPage, () => <Loading />, (error) => <
```
# changelog
```
v0.4.24
+upgrade to babel 7
+SSR support
+fix ie10
v0.4.22
!support old sid #issue 7
!withAdalLogin HOC componentWillMount deprecated removed
Expand Down
6 changes: 4 additions & 2 deletions lib/react-adal.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var AuthenticationContext = _adal["default"];
var isSSR = typeof window === 'undefined'; //fake context on SSR

var AuthenticationContext = isSSR ? function () {} : _adal["default"];
exports.AuthenticationContext = AuthenticationContext;
var redirectMessages = ['AADSTS16002', // old sid - https://github.com/salvoravida/react-adal/issues/46
'AADSTS50076', // MFA support - https://github.com/salvoravida/react-adal/pull/45
Expand Down Expand Up @@ -70,7 +72,7 @@ function adalGetToken(authContext, resourceGuiId, callback) {

function runWithAdal(authContext, app, doNotLogin) {
//SSR support
if (typeof window === 'undefined') {
if (isSSR) {
if (doNotLogin) app();
return;
} //it must run in iframe too for refreshToken (parsing hash and get token)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "react-adal",
"version": "0.4.23",
"version": "0.4.24",
"description": "Azure Active Directory (ADAL) support for ReactJS",
"main": "lib/react-adal.js",
"scripts": {
"compile": "cross-env NODE_ENV=production babel src --out-dir lib",
"prepublish": "npm run compile"
"build": "cross-env NODE_ENV=production babel src --out-dir lib",
"prepare": "npm run build",
"prepublishOnly": "npm run build"
},
"repository": {
"type": "git",
Expand Down
7 changes: 5 additions & 2 deletions src/react-adal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import React from 'react';
import AuthenticationContext_ from './adal';

export const AuthenticationContext = AuthenticationContext_;
const isSSR = typeof window === 'undefined';

//fake context on SSR
export const AuthenticationContext = isSSR? ()=>{} : AuthenticationContext_;

const redirectMessages = [
'AADSTS16002', // old sid - https://github.com/salvoravida/react-adal/issues/46
Expand Down Expand Up @@ -35,7 +38,7 @@ export function adalGetToken(authContext, resourceGuiId, callback) {

export function runWithAdal(authContext, app, doNotLogin) {
//SSR support
if (typeof window === 'undefined') {
if (isSSR) {
if (doNotLogin) app();
return;
}
Expand Down

0 comments on commit cdadbdf

Please sign in to comment.