mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
A living session could be a requirement for specific pages (like dashboards). If it doesn’t exist, the user should be redirected to a page asking them to sign in again.
Sometimes, a user might log out by accident, or by deleting cookies on purpose. If that happens (e.g. on a separate tab), then `useSession({ required: true })` should detect the absence of a session cookie and always return a non-nullable Session object type.
When `required: true` is set, the default behavior will be to redirect the user to the sign-in page. This can be overridden by an `action()` callback:
```js
const session = useSession({
required: true,
action() {
// ....
}
})
if (session.status === "Loading") return "Loading or not authenticated..."
// session.data is always defined here.
```
Co-authored-by: Kristóf Poduszló <kripod@protonmail.com>
Co-authored-by: Lluis Agusti <hi@llu.lu>
BREAKING CHANGE:
The `useSession` hook now returns an object. Here is how to accommodate for this change:
```diff
- const [ session, loading ] = useSession()
+ const { data: session, status } = useSession()
+ const loading = status === "loading"
```
With the new `status` option, you can test states much more clearly.
205 lines
5.2 KiB
JSON
205 lines
5.2 KiB
JSON
{
|
|
"name": "next-auth",
|
|
"version": "0.0.0-semantically-released",
|
|
"description": "Authentication for Next.js",
|
|
"homepage": "https://next-auth.js.org",
|
|
"repository": "https://github.com/nextauthjs/next-auth.git",
|
|
"author": "Iain Collins <me@iaincollins.com>",
|
|
"main": "index.js",
|
|
"types": "./index.d.ts",
|
|
"keywords": [
|
|
"react",
|
|
"nodejs",
|
|
"oauth",
|
|
"jwt",
|
|
"oauth2",
|
|
"authentication",
|
|
"nextjs",
|
|
"csrf",
|
|
"oidc",
|
|
"nextauth"
|
|
],
|
|
"exports": {
|
|
".": "./dist/server/index.js",
|
|
"./jwt": "./dist/lib/jwt.js",
|
|
"./react": "./dist/client/react.js",
|
|
"./providers": "./dist/providers/index.js",
|
|
"./providers/*": "./dist/providers/*.js",
|
|
"./errors": "./dist/lib/errors.js"
|
|
},
|
|
"scripts": {
|
|
"build": "npm run build:js && npm run build:css",
|
|
"build:js": "node ./config/build.js && babel --config-file ./config/babel.config.js src --out-dir dist",
|
|
"build:css": "postcss --config config/postcss.config.js src/**/*.css --base src --dir dist && node config/wrap-css.js",
|
|
"dev:setup": "npm i && npm run build:css && cd app && npm i",
|
|
"dev": "cd app && npm run dev",
|
|
"watch": "npm run watch:js | npm run watch:css",
|
|
"watch:js": "babel --config-file ./config/babel.config.js --watch src --out-dir dist",
|
|
"watch:css": "postcss --config config/postcss.config.js --watch src/**/*.css --base src --dir dist",
|
|
"test": "jest --config ./config/jest.config.js",
|
|
"test:ci": "npm run lint && npm run test:types && npm run test -- --ci",
|
|
"test:types": "dtslint types --onlyTestTsNext",
|
|
"prepublishOnly": "npm run build",
|
|
"lint": "eslint .",
|
|
"lint:fix": "eslint . --fix",
|
|
"version:pr": "node ./config/version-pr",
|
|
"website": "cd www && npm run start"
|
|
},
|
|
"files": [
|
|
"dist",
|
|
"index.js",
|
|
"index.d.ts",
|
|
"providers.js",
|
|
"providers.d.ts",
|
|
"adapters.js",
|
|
"adapters.d.ts",
|
|
"react.js",
|
|
"react.d.ts",
|
|
"errors.js",
|
|
"errors.d.ts",
|
|
"jwt.js",
|
|
"jwt.d.ts",
|
|
"internals"
|
|
],
|
|
"license": "ISC",
|
|
"dependencies": {
|
|
"@babel/runtime": "^7.14.6",
|
|
"futoin-hkdf": "^1.3.3",
|
|
"jose": "^1.27.2",
|
|
"jsonwebtoken": "^8.5.1",
|
|
"oauth": "^0.9.15",
|
|
"pkce-challenge": "^2.2.0",
|
|
"preact": "^10.5.13",
|
|
"preact-render-to-string": "^5.1.19"
|
|
},
|
|
"peerDependencies": {
|
|
"nodemailer": "^6.6.2",
|
|
"react": "^17.0.2",
|
|
"react-dom": "^17.0.2"
|
|
},
|
|
"peerOptionalDependencies": {
|
|
"nodemailer": "^6.6.2"
|
|
},
|
|
"peerDependenciesMeta": {
|
|
"nodemailer": {
|
|
"optional": true
|
|
}
|
|
},
|
|
"devDependencies": {
|
|
"@babel/cli": "^7.14.5",
|
|
"@babel/core": "^7.14.6",
|
|
"@babel/plugin-proposal-optional-catch-binding": "^7.14.5",
|
|
"@babel/plugin-transform-runtime": "^7.14.5",
|
|
"@babel/preset-env": "^7.14.7",
|
|
"@babel/preset-react": "^7.14.5",
|
|
"@testing-library/jest-dom": "^5.14.1",
|
|
"@testing-library/react": "^12.0.0",
|
|
"@testing-library/user-event": "^13.1.9",
|
|
"@types/nodemailer": "^6.4.2",
|
|
"@types/react": "^17.0.11",
|
|
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
|
"@typescript-eslint/parser": "^4.28.0",
|
|
"autoprefixer": "^10.2.6",
|
|
"babel-jest": "^27.0.5",
|
|
"babel-preset-preact": "^2.0.0",
|
|
"conventional-changelog-conventionalcommits": "4.6.0",
|
|
"cssnano": "^5.0.6",
|
|
"dtslint": "^4.1.0",
|
|
"eslint": "^7.29.0",
|
|
"eslint-config-prettier": "^8.3.0",
|
|
"eslint-config-standard-with-typescript": "^20.0.0",
|
|
"eslint-plugin-import": "^2.23.4",
|
|
"eslint-plugin-jest": "^24.3.6",
|
|
"eslint-plugin-node": "^11.1.0",
|
|
"eslint-plugin-promise": "^5.1.0",
|
|
"fs-extra": "^10.0.0",
|
|
"husky": "^6.0.0",
|
|
"jest": "^27.0.5",
|
|
"msw": "^0.30.0",
|
|
"next": "^11.0.1",
|
|
"postcss-cli": "^8.3.1",
|
|
"postcss-nested": "^5.0.5",
|
|
"prettier": "^2.3.1",
|
|
"pretty-quick": "^3.1.1",
|
|
"react": "^17.0.2",
|
|
"react-dom": "^17.0.2",
|
|
"typescript": "^4.3.4",
|
|
"whatwg-fetch": "^3.6.2"
|
|
},
|
|
"prettier": {
|
|
"semi": false
|
|
},
|
|
"eslintConfig": {
|
|
"parser": "@typescript-eslint/parser",
|
|
"parserOptions": {
|
|
"project": "./tsconfig.json"
|
|
},
|
|
"extends": [
|
|
"standard-with-typescript",
|
|
"prettier"
|
|
],
|
|
"ignorePatterns": [
|
|
"node_modules",
|
|
"test",
|
|
"next-env.d.ts",
|
|
"types",
|
|
"www",
|
|
".next",
|
|
"dist"
|
|
],
|
|
"globals": {
|
|
"localStorage": "readonly",
|
|
"location": "readonly",
|
|
"fetch": "readonly"
|
|
},
|
|
"overrides": [
|
|
{
|
|
"files": [
|
|
"./**/*test.js"
|
|
],
|
|
"env": {
|
|
"jest/globals": true
|
|
},
|
|
"extends": [
|
|
"plugin:jest/recommended"
|
|
],
|
|
"plugins": [
|
|
"jest"
|
|
]
|
|
}
|
|
]
|
|
},
|
|
"release": {
|
|
"branches": [
|
|
"+([0-9])?(.{+([0-9]),x}).x",
|
|
"main",
|
|
{
|
|
"name": "beta",
|
|
"prerelease": true
|
|
},
|
|
{
|
|
"name": "next",
|
|
"prerelease": true
|
|
}
|
|
],
|
|
"plugins": [
|
|
"@semantic-release/commit-analyzer",
|
|
"@semantic-release/release-notes-generator",
|
|
"@semantic-release/npm",
|
|
[
|
|
"@semantic-release/github",
|
|
{
|
|
"releasedLabels": false,
|
|
"successComment": false
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"funding": [
|
|
{
|
|
"type": "github",
|
|
"url": "https://github.com/sponsors/balazsorban44"
|
|
}
|
|
]
|
|
}
|