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

feat(useSession): support custom session id generator #390

Merged
merged 3 commits into from
Jun 20, 2023

Conversation

maou-shonen
Copy link
Contributor

Sometimes it may be necessary to customize the session ID.
for example, using something like crypto.randomBytes(20).toString('base64url').
having a method available in the session configuration would be convenient.

@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #390 (9fcc3e5) into main (e176ecc) will decrease coverage by 0.02%.
The diff coverage is 50.00%.

❗ Current head 9fcc3e5 differs from pull request most recent head 6b54bcf. Consider uploading reports for the commit 6b54bcf to get more accurate results

@@            Coverage Diff             @@
##             main     #390      +/-   ##
==========================================
- Coverage   76.19%   76.17%   -0.02%     
==========================================
  Files          26       26              
  Lines        2436     2439       +3     
  Branches      339      339              
==========================================
+ Hits         1856     1858       +2     
- Misses        580      581       +1     
Impacted Files Coverage Δ
src/utils/session.ts 22.27% <50.00%> (+0.61%) ⬆️

@maou-shonen
Copy link
Contributor Author

Do I need to create a session.test.ts?
Should I open another PR?

@pi0 pi0 changed the title feat: Customizable session ID generator feat(useSession): support custom session id generator Jun 9, 2023
@Atinux
Copy link
Member

Atinux commented Jun 12, 2023

What would be the use case to customize the ID generation?

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pi0
Copy link
Member

pi0 commented Jun 20, 2023

What would be the use case to customize the ID generation?

I have no usecase but makes sense to make id generation customizable (shorter, compatible with backend, more secure, crypto incompatibility, etc could be some reasons)

@pi0 pi0 merged commit 67e12ae into unjs:main Jun 20, 2023
3 checks passed
@maou-shonen
Copy link
Contributor Author

What would be the use case to customize the ID generation?

Obviously, I'm replying late,😅
One of my real-world use cases is that I can set the session ID to be the same as the ID from external login (usually OAuth2),
This way, I don't need to use two DB fields or session.data.id to associate them.

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.

None yet

3 participants