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

removed dead code, unsealData doesn't need ttl param #845

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The session data is stored in signed and encrypted cookies which are decoded by
- [`session.destroy(): void`](#sessiondestroy-void)
- [`session.updateConfig(sessionOptions: SessionOptions): void`](#sessionupdateconfigsessionoptions-sessionoptions-void)
- [`sealData(data: unknown, { password, ttl }): Promise<string>`](#sealdatadata-unknown--password-ttl--promisestring)
- [`unsealData<T>(seal: string, { password, ttl }): Promise<T>`](#unsealdatatseal-string--password-ttl--promiset)
- [`unsealData<T>(seal: string, { password }): Promise<T>`](#unsealdatatseal-string--password--promiset)
- [FAQ](#faq)
- [Why use pure cookies for sessions?](#why-use-pure-cookies-for-sessions)
- [How to invalidate sessions?](#how-to-invalidate-sessions)
Expand Down Expand Up @@ -188,7 +188,7 @@ Updates the configuration of the session with new session options. You still nee

This is the underlying method and seal mechanism that powers `iron-session`. You can use it to seal any `data` you want and pass it around. One usecase are magic links: you generate a seal that contains a user id to login and send it to a route on your website (like `/magic-login`). Once received, you can safely decode the seal with `unsealData` and log the user in.

### `unsealData<T>(seal: string, { password, ttl }): Promise<T>`
### `unsealData<T>(seal: string, { password }): Promise<T>`

This is the opposite of `sealData` and allow you to decode a seal to get the original data back.

Expand Down
8 changes: 1 addition & 7 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,7 @@ export function createSealData(_crypto: Crypto) {
export function createUnsealData(_crypto: Crypto) {
return async function unsealData<T>(
seal: string,
{
password,
ttl = fourteenDaysInSeconds,
}: { password: Password; ttl?: number },
{ password }: { password: Password },
): Promise<T> {
const passwordsMap = normalizeStringPasswordToMap(password);
const { sealWithoutVersion, tokenVersion } = parseSeal(seal);
Expand All @@ -241,7 +238,6 @@ export function createUnsealData(_crypto: Crypto) {
const data =
(await ironUnseal(_crypto, sealWithoutVersion, passwordsMap, {
...ironDefaults,
ttl: ttl * 1000,
})) ?? {};

if (tokenVersion === 2) {
Expand Down Expand Up @@ -365,7 +361,6 @@ export function createGetIronSession(
const session = sealFromCookies
? await unsealData<T>(sealFromCookies, {
password: passwordsMap,
ttl: sessionConfig.ttl,
})
: ({} as T);

Expand Down Expand Up @@ -452,7 +447,6 @@ async function getIronSessionFromCookieStore<T extends object>(
const session = sealFromCookies
? await unsealData<T>(sealFromCookies, {
password: passwordsMap,
ttl: sessionConfig.ttl,
})
: ({} as T);

Expand Down