baotoq / micro-commerce

ASP.NET Core 8.0, .NET Aspire, React, Nextjs, K8S, ELK stack, SonarQube
MIT License
71 stars 20 forks source link

Use secured API in nextjs #22

Open Misiu opened 2 years ago

Misiu commented 2 years ago

Is your feature request related to a problem? Please describe. I was searching for a clean way to use ASP. NET 5 API protected by identity server 4 in Nextjs. I found your. Repo, but sadly there is no sample how to use the secured API in next. I need SSR, SSG and client side usage.

Describe the solution you'd like Ideally the next example should show how to register and login using Identity Server 4 and Authnext and how to call protected API using nextjs on both client side and server side (Ssr).

Describe alternatives you've considered No alternatives :)

Additional context

baotoq commented 5 months ago

@Misiu we now have the next-auth example with server side and client access token retrieve

Misiu commented 5 months ago

@baotoq thank you for the update. One question about session management before I jump into code. This is a typical situation with the next-auth. Let's say your front is trying to make 5 requests to a protected API using an expired access token. The first call will get 401, then it will use the refresh token to obtain a new access token and new refresh token and finally will succeed, but the rest of the requests will use the old refresh token and will fail to refresh the access and refresh tokens. How will that work in your code?

I didn't watch your repo for a long time, but now I see many good things, especially .NET * and Aspire. Definitively will dig into the code :)

baotoq commented 5 months ago

have no idea how other people do it. but will copy some best practices from other repos