Skip to content

Commit

Permalink
Fix style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangvvo committed Sep 20, 2021
1 parent 6ef3988 commit c6e942c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export const config = {
#### `{ session }`

```javascript
import { session } from "next-session";
import nextConnect from "next-connect";
import { session } from 'next-session';
import nextConnect from 'next-connect';

const mySession = session(options);

Expand All @@ -73,7 +73,7 @@ export default handler;
#### `{ withSession }`

```javascript
import { withSession } from "next-session";
import { withSession } from 'next-session';

function handler(req, res) {
req.session.views = req.session.views ? req.session.views + 1 : 1;
Expand All @@ -87,7 +87,7 @@ export default withSession(handler, options);
#### `{ applySession }`

```javascript
import { applySession } from "next-session";
import { applySession } from 'next-session';

export default async function handler(req, res) {
await applySession(req, res, options);
Expand All @@ -110,7 +110,7 @@ export default async function handler(req, res) {
> Also, it is not reliable since `req` or `req.session` is only available on [server only](https://nextjs.org/docs/api-reference/data-fetching/getInitialProps#context-object)
```javascript
import { withSession } from "next-session";
import { withSession } from 'next-session';

function Page({ views }) {
return (
Expand All @@ -120,7 +120,7 @@ function Page({ views }) {

Page.getInitialProps = ({ req }) => {
let views;
if (typeof window === "undefined") {
if (typeof window === 'undefined') {
// req.session is only available on server-side.
req.session.views = req.session.views ? req.session.views + 1 : 1;
views = req.session.views;
Expand All @@ -135,7 +135,7 @@ export default withSession(Page, options);
#### `{ applySession }` ([`getServerSideProps`](https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering))

```javascript
import { applySession } from "next-session";
import { applySession } from 'next-session';

export default function Page({ views }) {
return (
Expand Down Expand Up @@ -165,11 +165,11 @@ export const options = { ...someOptions };

// Always import it at other places
// pages/index.js
import { options } from "foo/bar/session";
import { options } from 'foo/bar/session';
/* ... */
export default withSession(Page, options);
// pages/api/index.js
import { options } from "foo/bar/session";
import { options } from 'foo/bar/session';
/* ... */
await applySession(req, res, options);
```
Expand Down Expand Up @@ -204,11 +204,11 @@ You may supply a custom pair of function that _encode/decode_ or _encrypt/decryp

```javascript
// `express-session` signing strategy
const signature = require("cookie-signature");
const secret = "keyboard cat";
const signature = require('cookie-signature');
const secret = 'keyboard cat';
session({
decode: (raw) => signature.unsign(raw.slice(2), secret),
encode: (sid) => (sid ? "s:" + signature.sign(sid, secret) : null),
encode: (sid) => (sid ? 's:' + signature.sign(sid, secret) : null),
});
```

Expand All @@ -220,7 +220,7 @@ This allows you to **set** or **get** a specific value that associates to the cu

```javascript
// Set a value
if (loggedIn) req.session.user = "John Doe";
if (loggedIn) req.session.user = 'John Doe';
// Get a value
const currentUser = req.session.user; // "John Doe"
```
Expand All @@ -240,7 +240,7 @@ Save the session and set neccessary headers. Return Promise. It must be called b
You **must** call this if `autoCommit` is set to `false`.

```javascript
req.session.hello = "world";
req.session.hello = 'world';
await req.session.commit();
// always calling res.end or res.writeHead after the above
```
Expand All @@ -262,13 +262,13 @@ The session store to use for session middleware (see `options` above).
To use [Express/Connect stores](https://github.com/expressjs/session#compatible-session-stores), you may need to use `expressSession` from `next-session` if the store has the following pattern.

```javascript
const session = require("express-session");
const MongoStore = require("connect-mongo")(session);
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);

// Use `expressSession` as the replacement

import { expressSession } from "next-session";
const MongoStore = require("connect-mongo")(expressSession);
import { expressSession } from 'next-session';
const MongoStore = require('connect-mongo')(expressSession);
```

### Implementation
Expand Down
6 changes: 3 additions & 3 deletions src/connect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IncomingMessage, ServerResponse } from "http";
import { applySession } from "./core";
import { Options } from "./types";
import { IncomingMessage, ServerResponse } from 'http';
import { applySession } from './core';
import { Options } from './types';

export default function session(opts?: Options) {
return (
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { expressSession, promisifyStore } from "./compat";
export { default as session } from "./connect";
export { applySession } from "./core";
export { default as MemoryStore } from "./store/memory";
export { Options, SessionCookieData, SessionData, SessionStore } from "./types";
export { default as withSession } from "./withSession";
export { expressSession, promisifyStore } from './compat';
export { default as session } from './connect';
export { applySession } from './core';
export { default as MemoryStore } from './store/memory';
export { Options, SessionCookieData, SessionData, SessionStore } from './types';
export { default as withSession } from './withSession';
2 changes: 1 addition & 1 deletion src/withSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
NextApiHandler,
NextComponentType,
NextPage,
NextPageContext
NextPageContext,
} from 'next';
import { createElement } from 'react';
import { applySession } from './core';
Expand Down

0 comments on commit c6e942c

Please sign in to comment.