{"id":18387346,"url":"https://github.com/terryz/vuepress-login","last_synced_at":"2025-04-07T00:34:05.680Z","repository":{"id":39309461,"uuid":"224322753","full_name":"TerryZ/vuepress-login","owner":"TerryZ","description":"Add user authorization for VuePress","archived":false,"fork":false,"pushed_at":"2022-12-11T15:01:23.000Z","size":634,"stargazers_count":44,"open_issues_count":24,"forks_count":17,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T10:13:42.952Z","etag":null,"topics":["login","vue","vuejs","vuepress"],"latest_commit_sha":null,"homepage":"https://terryz.github.io/vuepress-login","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TerryZ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-27T01:59:19.000Z","updated_at":"2025-02-05T16:57:39.000Z","dependencies_parsed_at":"2023-01-27T01:30:38.021Z","dependency_job_id":null,"html_url":"https://github.com/TerryZ/vuepress-login","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TerryZ%2Fvuepress-login","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TerryZ%2Fvuepress-login/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TerryZ%2Fvuepress-login/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TerryZ%2Fvuepress-login/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TerryZ","download_url":"https://codeload.github.com/TerryZ/vuepress-login/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247574088,"owners_count":20960495,"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":["login","vue","vuejs","vuepress"],"created_at":"2024-11-06T01:25:47.273Z","updated_at":"2025-04-07T00:34:05.331Z","avatar_url":"https://github.com/TerryZ.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vuepress-login\n\nAdd user authorization for VuePress\n\n\u003ctemplate\u003e\n\u003cbutton type=\"button\" @click=\"clear\"\u003eClear login status\u003c/button\u003e\n\u003c/template\u003e\n\n## Examples\n\nLive examples in below sites\n\n- [github.io](https://terryz.github.io/vuepress-login)\n- [gitee.io](https://terryz.gitee.io/vuepress-login)\n\nEnter any username and password for experience\n\n## Source code\n\nPlease visit [https://github.com/TerryZ/vuepress-login](https://github.com/TerryZ/vuepress-login)\n\n## Install plugin\n\nInstall `v-dialogs` plugin for Modal dialog\n\n```\n# npm\nnpm i v-dialogs -D\n\n# yarn\nyarn add -D v-dialogs\n```\n\n## Create login form file\n\nAdd `Login.vue` file for login form, display in Modal dialog\n\n```vue\n\u003ctemplate\u003e\n  \u003cdiv class=\"login-form\"\u003e\n    \u003cdiv class=\"form-header\"\u003eUser Name\u003c/div\u003e\n    \u003cdiv\u003e\n      \u003cinput type=\"text\" class=\"form-control\" v-model=\"username\"\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"form-header\"\u003ePassword\u003c/div\u003e\n    \u003cdiv\u003e\n      \u003cinput type=\"password\" class=\"form-control\" v-model=\"password\"\u003e\n    \u003c/div\u003e\n\n    \u003cdiv class=\"btn-row\"\u003e\n      \u003cbutton class=\"btn\" @click=\"login\"\u003e\n        OK\n      \u003c/button\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nimport { STORAGE_KEY } from './helper'\n\nexport default {\n  data () {\n    return {\n      username: '',\n      password: ''\n    }\n  },\n  methods: {\n    login () {\n      if (this.username \u0026\u0026 this.password) {\n        const data = JSON.stringify({\n          name: this.username,\n          time: new Date().getTime()\n        })\n        window.localStorage.setItem(STORAGE_KEY, data)\n        this.$emit('close', true)\n      } else {\n        this.$dlg.alert('Please complete the content', {\n          messageType: 'warning'\n        })\n      }\n    }\n  }\n}\n\u003c/script\u003e\n\n\u003cstyle lang=\"stylus\"\u003e\n.login-form\n  padding: 1rem\n  display flex\n  flex-direction column\n  box-sizing border-box\n  .btn-row\n    margin-top 1rem\n  .btn\n    padding 0.6rem 2rem\n    outline none\n    background-color #60C084\n    color white\n    border 0\n  .form-header\n    color #666\n    margin-bottom 0.5rem\n  .form-control\n    padding 0.6rem\n    border 2px solid #ddd\n    width 100%\n    margin-bottom 0.5rem\n    box-sizing border-box\n    outline none\n    transition border 0.2s ease\n    \u0026:focus\n      border 2px solid #aaa\n\u003c/style\u003e\n```\n\n## VuePress Configuration\n\nAdd `enhanceApp.js` file in `/.vuepress`\n\n```js\nimport { checkAuth } from './login/helper'\nimport Login from './login/Login'\n\nexport default ({\n  Vue,\n  options,\n  router,\n  siteData\n}) =\u003e {\n  Vue.mixin({\n    mounted() {\n      const doCheck = () =\u003e {\n        if (!checkAuth()) {\n          this.$dlg.modal(Login, {\n            width: 300,\n            height: 350,\n            title: 'Employee login',\n            singletonKey: 'employee-login',\n            maxButton: false,\n            closeButton: false,\n            callback: data =\u003e {\n              if (data === true) {\n                // do some stuff after login\n              }\n            }\n          })\n        }\n      }\n\n      if (this.$dlg) {\n        doCheck()\n      } else {\n        import('v-dialogs').then(resp =\u003e {\n          Vue.use(resp.default)\n          this.$nextTick(() =\u003e {\n            doCheck()\n          })\n        })\n      }\n    }\n  })\n}\n```\nWill do user authorization verify in every document\n\n- If not authorized, show login Modal dialog\n- If authorized, going to visit vuepress documentation\n\n\u003cscript\u003e\nexport default {\n  methods: {\n    clear () {\n      window.localStorage.clear()\n      alert('User login status has been cleared!');\n    }\n  }\n}\n\u003c/script\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterryz%2Fvuepress-login","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterryz%2Fvuepress-login","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterryz%2Fvuepress-login/lists"}