adding middleware in Next js with laravel breeze API - api

I have a la laravel breeze api app i just created, then associated a next.js app as frontend. I am trying to spscify a middleware from laravel into next.js pages but i am not sure how it works. documentation is not clear either.
Read the documentation, when through several vdieos but i am not finding anything realted

Related

Nuxt 3 Authentication with Laravel 9 and Sanctum

I'm using nuxt 3 for a project and can't find an easy way to do authentication with Laravel and Sanctum.
The #nuxtjs/axios module is only compatible for nuxt 2 and the package a developer provided for nuxt 3 (#nuxtjs-alt/auth) doesn't provide much documentation. I tried to implement it but nuxtApp().$auth always returns undefined.
How can I authenticate my user in the Login screen and then have an auth middleware to secure my routes? I reiterate the use of NUXT3
Just found this Nuxt 3 sanctum package on GitHub:
https://github.com/dystcz/nuxt-sanctum-auth
Seems like a solution until the official auth module is published for nuxt3.

Next.js with express.js or without express.js?

I have seen many people using nextjs with expressjs and without expressjs framwork. Can someone please explain why do we need expressjs with nextjs? Nextjs works as SSR without expressjs. What does expressjs add to nextjs when we use it together? Assuming that we are using different rest api server.
You don't need to use expressjs if all you want is server-side rendering. But if you want to go beyond that by adding an API, as an example, then you need to be able to override the routing and that's when you'd add expressjs in front. Express will get the request and see if it is for the API or if it's just a normal nextjs page. LogRocket has a very good tutorial on this https://blog.logrocket.com/how-to-build-a-server-rendered-react-app-with-next-express-d5a389e7ab2f/
You most likely don't need to override Next's default server. For edge cases where you do, you'll see examples showing a custom server extending Next's default. You can use whatever server framework you want – Express, Hapi, etc.
https://nextjs.org/docs/advanced-features/custom-server

React SPA app with .net core backend and .net identity

I basically have the same question as what is detailed here: Login redirect with asp.Core 2.0 and React. But that post never got an answer.
I've searched quite a bit and pretty much my problem is also touched on here here: https://github.com/aspnet/JavaScriptServices/issues/1440
I want to create a react front end application, but use .net core for the backend. I've used the .net core template with react redux as my boilerplate. I've also configured the .net identity on my backend. So I can actually use [Authorize] on my api calls and it works. By this I mean that if someone is authenticated the api returns data and if no one is authenticated it returns whatever the default redirect page is. I can confirm this by looking at the response on my chrome debugger and I see that it is showing the html for the register page which I've defaulted my login path to in configureapplicationcookie options.
The boiler plate is setup to serve up pages from the react client folder and uses react router. Therefore, I cannot set up any links to pages on my server. However, I'm able to manually navigate to my server pages for example /Account/Login and successfully login. My api calls through the links on the react front end then seem to work just as I would like.
What I would like to do is:
make calls from my react application to my server api
upon unsuccessful access to any api endpoint, redirect the user/request to my register page on the .net core server
have the user register and/or login and then redirect them to the route they came from through the react application.
Is this possible? Is it advisable?
I understand that you can manage all this on the front end using IdentityServer as detailed here: http://docs.identityserver.io/en/release/quickstarts/7_javascript_client.html. However, if all the infrastructure can be quickly spun up in .net and I can leverage the authentication templates, then I want to experiment with that setup and save time. Plus if this is feasible, why bother doing the setup on the front end using a 3rd party login provider? What am I missing?

Am building an App using Angular 2 and backend as Shopify Api, While calling Shopify API using Angular 2 am getting issue CORS-ORIGIN error

Look at the API i used
https://{{apikey}}:{{password}}#{{yourstore}}.myshopify.com/admin/products.json
while calling the Shopify API in Post Man it's working, data is getting from Shopify Store
Problem is that While calling API in Angular 2 only getting the issue "CORS-ORIGIN"
You should not make front-end calls to the API as that exposes your private API Key to the world. You can re-think your pattern of use here with a read up on using API App Proxy calls. You can thn safely make XHR calls using the App Proxy to call the API and return results. No more CORS problems and security!

Is it feasible to convert an single MVC razor view/page into a SPA?

I currently have an ASP.NET Core MVC application with multiple pages with one particular page having a lot of hand-made javascript code and ajax requests. It's becoming quite hard to manage and I would like to move to a framework like Angular, React etc for this particular page only. It is feasible to convert a single MVC view to a SPA app and still keep the other pages? Does anyone have any references on this? Google is not being too helpful...
The simplest way I have found to do this is to use one of the SPA templates and then add the static pages around that.
Here's an an example project I have made that demonstrates the concept by adding a new Razor Page to the angular SPA template.
To do this for an already existing MVC/Razor Pages app I would suggest copying the following from an SPA template project to the MVC/Razor Pages app:
ClientApp
Controllers (SampleDataController.cs)
Views (Home, Shared)
npm_shrinkwrap.json
package.json
tsconfig.json
webpack.config.json
webpack.config.vendor.json
Startup.cs (copy the SPA things)
This is not an exhaustive list but should get someone most of the way.