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

Add option for nuxtServerInit to NOT dispatch getInitialData #214

Closed
thomasv opened this issue Dec 9, 2021 · 5 comments · Fixed by #229
Closed

Add option for nuxtServerInit to NOT dispatch getInitialData #214

thomasv opened this issue Dec 9, 2021 · 5 comments · Fixed by #229

Comments

@thomasv
Copy link

thomasv commented Dec 9, 2021

We use nuxtjs/auth-next and our TYPO3 is only accessible for authorized users (we use oauth2 and redirect unauthorized users to an external login form).

It would be great to NOT call getInitialData in nuxtServerInit when users are not authorized. In this way we could detect in our application's nuxtServerInit the login state and set some flag (maybe in typo3-store or an option like getInitialDataAutomatically) to dispatch or not dispatch the getInitialData or directly dispatch the nuxtServerInit of nuxt-typo3.

Would this be an idea to get nuxt-typo3 work with nuxt-auth or is there another approach?

@thomasv
Copy link
Author

thomasv commented Dec 9, 2021

Another (bigger) problem is, that we have to send an Authorization Header with the token to our TYPO3. But we have access to the token only on client side but the getInitialData is always called on server side. So, in our case, I think we have to avoid the server side dispatch and move it to the client (after successful log in).

@mercs600
Copy link
Contributor

mercs600 commented Dec 10, 2021

@thomasv I understand the possibility to override store logic, so I have prepared a simple PR feat: add option for disable store (#214) #216

You can disable the store and provide your own logic - I have prepared an example in the PR. Please test it, let me know if that resolves your issue.

But I don't understand why you can't call getInitialData for the non-logged-in users - you could detect token on the API side and return something which is ok for the not-logged-in users.

Please notice also that getInitialData is called not only in nuxtServerInit - we use this method also when language locale is changed -> https://github.com/TYPO3-Initiatives/nuxt-typo3/blob/master/lib/lib/i18n.js#L44 -> by middleware -> https://github.com/TYPO3-Initiatives/nuxt-typo3/blob/master/lib/middleware/i18n.js

So when you override the store logic, you have also to take care of getInitialData method to avoid calling API there.

We haven't worked with nuxt/auth yet (I have to check, can we integrate it with felogin) but currently we use felogin cookie to detect if a user is logged in or not. API requests based on this cookie deliver a different response for initialData.

@thomasv
Copy link
Author

thomasv commented Dec 13, 2021

@mercs600 Thanks you.

Yes, you are right. We could configure the api response for unauthorized users, but in our architecture and use cases we do not have any dealing with non-logged-in users. So, we decided to request the typo3 backend only in logged-in status.

Thanks for the PR. I think this is a good option in general to have own control. In our case, it is sufficient, if we call typo3/nuxtServerInit from our nuxtServerInit like I mentioned. In this way, we have control over the getInitialData request.

Right, getInitialData is called client side, too. This would be another approach to dispatch it after successful login.

@mercs600
Copy link
Contributor

@thomasv Ok I get it.

We will extend store functionalities soon.

@mercs600
Copy link
Contributor

@thomasv please look at it #229

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