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

Setup cookie option #9

Merged
merged 5 commits into from Oct 17, 2022
Merged

Setup cookie option #9

merged 5 commits into from Oct 17, 2022

Conversation

Octo8080X
Copy link
Owner

Hello, @xstevenyung.

Both cookie sessions and redis sessions use cookies, but I was unable to set cookie options, so I added a feature.
Specifically, I wanted to set max-age, http-only, etc.

For example.

/// _middleware.ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
import { CreateCookieSession, WithSession } from "fresh-session";

export type State = {} & WithSession;

const cookieSession = CreateCookieSession({maxAge: 30, httpOnly: true});

export function handler(req: Request, ctx: MiddlewareHandlerContext<State>) {
  return cookieSession(req, ctx);
}
/// _middleware.ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
import { CreateRedisSession, WithSession } from "fresh-session/mod.ts";
import { connect } from "redis/mod.ts";
export type State = WithSession;

const redis = await connect({
  hostname: "redis",
  port: 6379,
});

const redisSession = CreateRedisSession(redis, "session_", { maxAge: 10 });

function session(req: Request, ctx: MiddlewareHandlerContext<State>) {
  if (req.url === `http://localhost:${ctx.localAddr?.port}/`) {
    return redisSession(req, ctx);
  }
  return ctx.next();
}
export const handler = [session];

@Octo8080X Octo8080X added the WIP label Oct 10, 2022
src/stores/cookie.ts Outdated Show resolved Hide resolved
@xstevenyung
Copy link
Collaborator

Looking pretty good so far, I made some feedback. Can you also add some documentation for those ?

@Octo8080X
Copy link
Owner Author

Thanks for checking it out.

Feedback has been reflected and the README and example have been updated.

The module reference in example is now 0.1.9.

Copy link
Collaborator

@xstevenyung xstevenyung left a comment

Choose a reason for hiding this comment

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

Some minor changes to make the doc / API a little simpler (this is nitpicking at this point).

otherwise, really nice work 👍

amazing work on the doc 👏

src/stores/cookie.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@Octo8080X
Copy link
Owner Author

I have corrected the areas you pointed out.

I think it is now much simpler.

Thanks.

Copy link
Collaborator

@xstevenyung xstevenyung left a comment

Choose a reason for hiding this comment

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

looking good, I will run some test when I will be off the train and mark a new release 👍

@xstevenyung xstevenyung merged commit 2edabff into Octo8080X:main Oct 17, 2022
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

2 participants