{"id":14384559,"url":"https://github.com/hackerart/nextjs-auth-hoc","last_synced_at":"2025-08-23T17:32:46.252Z","repository":{"id":181475384,"uuid":"200169575","full_name":"hackerart/nextjs-auth-hoc","owner":"hackerart","description":"A Higher Order Component for restricting page access.","archived":false,"fork":false,"pushed_at":"2020-01-05T09:36:06.000Z","size":99,"stargazers_count":9,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-15T08:06:08.132Z","etag":null,"topics":["acl","authorization","hoc","nextjs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackerart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-08-02T05:15:35.000Z","updated_at":"2022-04-11T18:12:20.000Z","dependencies_parsed_at":"2024-01-14T20:16:54.012Z","dependency_job_id":"b188d6d8-3682-4fbe-832b-a2f927fc4243","html_url":"https://github.com/hackerart/nextjs-auth-hoc","commit_stats":null,"previous_names":["hackerart/nextjs-auth-hoc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerart%2Fnextjs-auth-hoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerart%2Fnextjs-auth-hoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerart%2Fnextjs-auth-hoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerart%2Fnextjs-auth-hoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackerart","download_url":"https://codeload.github.com/hackerart/nextjs-auth-hoc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230716557,"owners_count":18269790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["acl","authorization","hoc","nextjs"],"created_at":"2024-08-28T18:01:28.484Z","updated_at":"2024-12-21T12:30:42.356Z","avatar_url":"https://github.com/hackerart.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# nextjs-auth-hoc\n\n[![NPM version][npm-image]][npm-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: http://img.shields.io/npm/v/nextjs-auth-hoc.svg?style=flat-square\n[npm-url]: http://npmjs.org/package/nextjs-auth-hoc\n[download-image]: https://img.shields.io/npm/dm/nextjs-auth-hoc.svg?style=flat-square\n[download-url]: https://npmjs.org/package/nextjs-auth-hoc\n\nA Higher Order Component for restricting page access.\n\n## Installation\n[![nextjs-auth-hoc](https://nodei.co/npm/nextjs-auth-hoc.png)](https://npmjs.org/package/nextjs-auth-hoc)\n\n    // with npm\n    npm install nextjs-auth-hoc\n    \n    // with yarn\n    yarn add nextjs-auth-hoc\n\n## Configuration\nBefore using you have to specify some variables in .env of your project:\n    \n    # Default page to redirect users if user is not authenticated\n    REDIRECT_IF_NOT_AUTHENTICATED=/auth/signin\n    \n    # Default page to redirect if user is authenticated\n    REDIRECT_IF_AUTHENTICATED=/dashboard\n    \n    # Default page to redirect if action is not authorized\n    REDIRECT_IF_NO_ACCESS=/dashboard\n    \n    # Name of cookie key for JWT token storage\n    JWT_COOKIE_NAME=jwt\n    \n    # Host of site, only need if your authentication happens on other domain\n    # It needed to pass \"ref\" query\n    REFERER=http://example.com\n    \n    # Base URL of root endpoint\n    API_HOST=http://api.example.com/v1\n    \n    # URL to get user session\n    # if not specified default will be \"/auth/session\"\n    GET_SESSION_URL=/user/profile\n\n## Usage\nHere is a quick example to get you started, **it's all you need**:\n\n    import React from 'react';\n    import { Auth } from 'nextjs-auth-hoc';\n    \n    class Posts extends React.Component {\n\t    static async getInitialProps() {\n            return {};\n\t    }\n\t    \n        render() {\n            const { user: { token } } = this.props // You also can access user object\n            return (\n                \u003cdiv\u003eList of posts\u003c/div\u003e\n            );\n\t    }\n    }\n    export default Auth({ action: 'RINA' })(Posts)\n    \nThere is also a special HOC withUser to access user object, **it's all you need**:\n\n    import React from 'react';\n    import { withUser } from 'nextjs-auth-hoc';\n    \n    const Header = (props) =\u003e {\t    \n        return (\n            \u003cdiv\u003e{props.user.name}\u003c/div\u003e\n        )\n    }\n    export default withUser(Header)\n    \nYou can restrict accessing page by passing ACL option, **it's all you need**:\n    \n    import React from 'react';\n    import { Auth } from 'nextjs-auth-hoc';\n    \n    class Dashboard extends React.Component {\n        static async getInitialProps() {\n            return {};\n        }\n        \n        render() {\n            const { user: { token } } = this.props // You also can access user object\n            return (\n                \u003cdiv\u003eList of posts\u003c/div\u003e\n            );\n        }\n    }\n    export default Auth({ action: 'RINA', ACL: ['admin'] })(Dashboard)\n\n## API  \n\n### action (**optional**)\n type: **\"string\"**\n \n|   value  |  description  |  \n|----------|---------------|  \n|   RINA   | Redirect if not authenticated  \n|   RIA    | Redirect if authenticated  \n  \n### ACL (**optional**)\ntype: **\"array\"**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackerart%2Fnextjs-auth-hoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackerart%2Fnextjs-auth-hoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackerart%2Fnextjs-auth-hoc/lists"}