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

Using react-adal with Server Side Rendering(Next.js) #67

Closed
M0W93 opened this issue May 10, 2019 · 9 comments
Closed

Using react-adal with Server Side Rendering(Next.js) #67

M0W93 opened this issue May 10, 2019 · 9 comments

Comments

@M0W93
Copy link

M0W93 commented May 10, 2019

Hello,
actually im trying to use react-adal with Next.js, but because of the ´window´ reference in the library it isn't possible to use it with SSR.

Correct me if im wrong but isn't it insecure to deliver the whole adalConfig (with clientId) to the browser?

@salvoravida
Copy link
Owner

no because clientId si just tell MS azure which AzureWebApp is going to login. there is no other way. authentication is from user pc to Azure not your server to Azure - it is a SPA application

@salvoravida
Copy link
Owner

hum, if your full app is protected under login, it is unuseful to render before login.

anyway if your app has just only a private section, then probably i will update the lib with a check on window object

@salvoravida
Copy link
Owner

salvoravida commented May 17, 2019

@M0W93 try v0.4.23

please share feedback if it is ok on SSR

@M0W93
Copy link
Author

M0W93 commented May 17, 2019

Thanks a lot for your effort.
I will try this out later and will give you a feedback.

@M0W93
Copy link
Author

M0W93 commented May 20, 2019

Hello @salvoravida,
i tried the new react-adal version but get the following error:

window._adalInstance = this;
  ^

ReferenceError: window is not defined

on react-adal/lib/adal.js:141

@salvoravida
Copy link
Owner

@M0W93 try 0.4.24
please share feedback if it is ok on SSR

@saostad
Copy link

saostad commented Jun 28, 2019

Hi, I tried to use it in my sample app but I am not sure how to set it up?
I am using next.js@8.1.0 and react-adal@0.4.24
Error:

TypeError: authContext.acquireToken is not a function
    at C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\react-adal\lib\react-adal.js:53:17
    at new Promise (<anonymous>)
    at adalGetToken (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\react-adal\lib\react-adal.js:52:10)
    at new _temp (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\react-adal\lib\react-adal.js:141:9)
    at processChild (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\react-dom\cjs\react-dom-server.node.development.js:2846:14)
    at resolve (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\react-dom\cjs\react-dom-server.node.development.js:2812:5)
    at ReactDOMServerRenderer.render (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\react-dom\cjs\react-dom-server.node.development.js:3202:22)
    at ReactDOMServerRenderer.read (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\react-dom\cjs\react-dom-server.node.development.js:3161:29)
    at renderToString (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\react-dom\cjs\react-dom-server.node.development.js:3646:27)
    at render (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\next-server\dist\server\render.js:86:16)
    at renderPage (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\next-server\dist\server\render.js:211:20)
    at Function.value (C:\Users\SOstad\Projects\tests\with-ant-design-app\.next\server\static\development\pages\_document.js:555:41)
    at Object.loadGetInitialProps (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\next-server\dist\lib\utils.js:42:35)
    at Object.renderToHTML (C:\Users\SOstad\Projects\tests\with-ant-design-app\node_modules\next-server\dist\server\render.js:218:36)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)

My Component Code:

import React from "react";
import { withAdalLoginApi } from "./adalConfig";

function IndexComponent() {
  return (
    <div style={{ marginTop: 100 }}>
      <h1>Hello</h1>
    </div>
  );
}

export default withAdalLoginApi(IndexComponent, IndexComponent, IndexComponent);

@salvoravida
Copy link
Owner

@saostad it should be fixed on v0.5.0

let me know your feedback!

@salvoravida salvoravida unpinned this issue Sep 28, 2019
@apatel6152
Copy link

React adal latest version is not compatible with react 18 right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants