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

chore: add back silent auth middleware #5

Merged
merged 1 commit into from
Sep 11, 2024
Merged

Conversation

RomainLanz
Copy link
Member

Hey there! 👋🏻

This PR reintroduces the SilentAuth middleware.

Why was it removed?

The middleware was previously removed because the preferred approach was to call auth.check() directly wherever the auth.user variable is needed in your templates. This is often done in files like header.edge:

@if(auth.isAuthenticated || await auth.check())
  {{ auth.user.email }}
@end

Why bring it back?

There are a few reasons:

  1. When using an API with the session guard, there may be no templates involved, making the SilentAuth middleware quite useful.
  2. Its removal has led to some confusion, as the documentation doesn't clearly explain everything.

For these reasons, I believe the silent_auth middleware should be re-added, along with improved documentation on when it can be helpful.

@thetutlage
Copy link
Member

May I know how the usage looks like with the API?

@RomainLanz
Copy link
Member Author

May I know how the usage looks like with the API?

Same as with a standard SSR application.
You add the middleware in router.use inside your kernel.ts.

@thetutlage
Copy link
Member

No I mean, in what use-case an API needs the logged-in user for a public API route

@RomainLanz
Copy link
Member Author

Error handling, logging, access management, HAL / HATEOS, and many other needs.

@thetutlage
Copy link
Member

Makes sense!

@thetutlage
Copy link
Member

Should we register the middleware as well?

@RomainLanz
Copy link
Member Author

RomainLanz commented Sep 4, 2024

Should we register the middleware as well?

I believe we should document how it works but not register it by default. Some people may still prefer to manage exactly when authentication is performed.

At least now, they can simply register a new middleware (same as V5)

@thetutlage
Copy link
Member

@RomainLanz Can you please open a PR for the docs as well?

@thetutlage thetutlage merged commit 4a1a695 into 2.x Sep 11, 2024
10 checks passed
@thetutlage thetutlage deleted the feat/silent_auth branch September 11, 2024 02:27
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

Successfully merging this pull request may close these issues.

2 participants