feature(session): add session middleware#1188
Conversation
🦋 Changeset detectedLatest commit: 9281235 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
0c660b6 to
afe03e9
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1188 +/- ##
===========================================
- Coverage 79.32% 63.45% -15.88%
===========================================
Files 81 100 +19
Lines 2443 3467 +1024
Branches 633 911 +278
===========================================
+ Hits 1938 2200 +262
- Misses 419 1029 +610
- Partials 86 238 +152
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ad26303 to
1a85b15
Compare
42dbe54 to
4bea706
Compare
4bea706 to
4f11809
Compare
| useSession({ secret }) | ||
| ) | ||
|
|
||
| app.get('/session', async (c) => { |
There was a problem hiding this comment.
I updated the examples to the "not chained" style. It's common for users. If you pass SessionEnv to Hono as a generic, you can write it like this.
There was a problem hiding this comment.
Makes sense, thank you!
|
Looks good to me! I like this middleware. I'll create some examples using it later. Thank you! |
I've been replacing an authentication library in a Next.js application, and thought it would be a good contribution to make. This PR is only focusing on the session middleware.
It started out as a library to bridge the gap between the previous authentication library and a new library. It runs on Cloudflare Workers, so the library gradually evolved into a standalone worker. This latest iteration is now middleware for a Hono app. It's been in progress for a while now.
I've done a lot of reading and research along the way. Some key resources that I've used include:
openid-clientjoseexpress-sessionI also looked at using other similar libraries and frameworks including..
@hono/oidc-auth..all of which do a lot more than I need, like account and database management, or don't expose the functionality I'm after. Specifically, an OIDC-client service to manage sessions and access/id/refresh tokens, while acting as an auth middleware proxying requests to upstream services.
What I'm essentially after is OAuth2 Proxy that I can run in Cloudflare Workers 😅
There are a few other's out there with similar needs, so I thought I'd share the end result.