workos / authkit-nextjs

The WorkOS library for Next.js provides convenient helpers for authentication and session management using WorkOS & AuthKit with Next.js.
MIT License
58 stars 14 forks source link

export `cookieName`, `cookieOptions` and `encryptSession` #27

Closed nirtamir2 closed 1 week ago

nirtamir2 commented 6 months ago

This PR export cookieOptions, cookieName and encryptSession from WorkOS. The motivation to do it is for people who try to implement the authentication themself and need to copy the code from this repository (that may change in the future). Also, I need to install iron-session as a dependency in my project if I implement it myself.

Alternatively, I could create a function that sets the cookie like the SDK instead of writing this code the codebase:

        const session = await encryptSession({ accessToken, refreshToken, user, impersonator });
        cookies().set(cookieName, session, cookieOptions);

Notes:

I still haven't organized everything properly with my implementation, but it seems like I need to export those parts from the SDK to implement it. Feel free to change or block this PR if you feel it's wrong :)

PaulAsjes commented 5 months ago

Thanks for the PR! We're going to discuss a bit internally on what the best course of action here is. We're thinking in particular on how we can make some high-level abstractions to make this easier on you.

gabrielalmeida commented 4 months ago

High-level abstractions would be great but just exporting those would make the library useful to anyone migrating from other session management implementations, right now it assumes you don't have a previous one in place.

We are doing the same copy/paste + iron-session dependency to properly migrate our users from their previous sessions.

PaulAsjes commented 1 week ago

Higher level abstractions now exist in the Node SDK: https://workos.com/docs/reference/user-management/session-helpers