-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- cookie设置要 禁用secure,因为本地开发是 http 不是https - withSession 处理session操作 - 给 NextApiRequest 添加自定义的属性
- Loading branch information
Showing
6 changed files
with
241 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {withIronSession} from 'next-iron-session'; | ||
import {NextApiHandler} from 'next'; | ||
|
||
export function withSession(handler: NextApiHandler) { | ||
return withIronSession(handler, { | ||
// password: process.env.SECRET_COOKIE_PASSWORD, | ||
password: 'c2a85490-cc60-4f21-94e8-8dc5dd3220da', //密钥,这个应该用环境变量 | ||
cookieName: 'blog', | ||
// 这个选项如果不设置 你本地开发是http的 就会种不下 cookie 获取 user 会是 undefined | ||
cookieOptions: {secure: false} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> | ||
import * as next from 'next'; | ||
|
||
declare module "*.png" { | ||
const value: string; | ||
export default value; | ||
} | ||
|
||
|
||
declare module 'next' { | ||
import {Session} from 'next-iron-session'; | ||
|
||
interface NextApiRequest { | ||
session: Session | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.