Skip to content

Commit a92ebb7

Browse files
Merge pull request #48 from what-crud/issue/47_add_auth_config_section_in_docs
Issue/47 add auth config section in docs
2 parents b1b55db + 0a4ade6 commit a92ebb7

File tree

1 file changed

+102
-45
lines changed

1 file changed

+102
-45
lines changed

docs/guide/essentials/configuration.md

Lines changed: 102 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Create **api.js** file in **src/config** directory. You may use template located
1414
#### src/config/api.js:
1515

1616
```js
17-
export const api = {
17+
export default {
1818
url: 'http://crm-api.id-a.pl/',
1919
path: {
2020
default: 'api',
@@ -38,7 +38,7 @@ The **examples/`example`/config** folder also contains the **main.js** file. Cop
3838
#### src/config/main.js:
3939

4040
``` js
41-
export const main = {
41+
export default {
4242
title: "Vue CRUD",
4343
locales: [{
4444
name: 'en',
@@ -78,7 +78,7 @@ Create **crud.js** file in **src/config** directory. You may use template locate
7878
#### src/config/crud.js:
7979

8080
```js
81-
export const crud = {
81+
export default {
8282
activityColumnName: 'active',
8383
primaryKey: 'id',
8484
deleteMode: 'soft',
@@ -124,20 +124,94 @@ export const crud = {
124124
```
125125

126126
Parameters:
127-
- `activityColumnName` - default: *'active'* - default CRUD.vue component's `activityColumnName` property value,
128-
- `primaryKey` - default: *'id'* - default CRUD.vue component's `primaryKey` property value,
129-
- `deleteMode` - default: *'soft'* - default CRUD.vue component's `deleteMode` property value,
130-
- `editButton` - default: *true* - default CRUD.vue component's `editButton` property value,
131-
- `createMode` - default: *true* - default CRUD.vue component's `createMode` property value,
132-
- `editMode` - default: *true* - default CRUD.vue component's `editMode` property value,
133-
- `mainFilter` - default: *true* - default CRUD.vue component's `mainFilter` property value,
134-
- `fieldFilter` - default: *true* - default CRUD.vue component's `fieldFilter` property value,
135-
- `exportButton` - default: *true* - default CRUD.vue component's `exportButton` property value,
136-
- `refreshButton` - default: *true* - default CRUD.vue component's `refreshButton` property value,
137-
- `selectManyMode` - default: *true* - default CRUD.vue component's `selectManyMode` property value,
138-
- `updateManyMode` - default: *true* - default CRUD.vue component's `updateManyMode` property value,
139-
- `removeManyMode` - default: *true* - default CRUD.vue component's `removeManyMode` property value,
140-
- `fieldModifiers` - default: *{}* - Object with list of functions modifying the contents of fields in the table
127+
- `activityColumnName` - default: `'active'` CRUD.vue component's `activityColumnName` property value,
128+
- `primaryKey` - default: `'id'` CRUD.vue component's `primaryKey` property value,
129+
- `deleteMode` - default: `'soft'` CRUD.vue component's `deleteMode` property value,
130+
- `editButton` - default: `true` CRUD.vue component's `editButton` property value,
131+
- `createMode` - default: `true` CRUD.vue component's `createMode` property value,
132+
- `editMode` - default: `true` CRUD.vue component's `editMode` property value,
133+
- `mainFilter` - default: `true` CRUD.vue component's `mainFilter` property value,
134+
- `fieldFilter` - default: `true` CRUD.vue component's `fieldFilter` property value,
135+
- `exportButton` - default: `true` CRUD.vue component's `exportButton` property value,
136+
- `refreshButton` - default: `true` CRUD.vue component's `refreshButton` property value,
137+
- `selectManyMode` - default: `true` CRUD.vue component's `selectManyMode` property value,
138+
- `updateManyMode` - default: `true` CRUD.vue component's `updateManyMode` property value,
139+
- `removeManyMode` - default: `true` CRUD.vue component's `removeManyMode` property value,
140+
- `fieldModifiers` - default: `{}` - Object with list of functions modifying the contents of fields in the table
141+
142+
### Authentication
143+
Create **auth.js** file in **src/config** directory. You may use template located in **examples/`example`/config/auth.js**. Here you can set default authentication configuration.
144+
145+
#### src/config/auth.js:
146+
147+
```js
148+
export default {
149+
api: 'http://127.0.0.1:8000/api',
150+
prefix: 'auth',
151+
paths: {
152+
login: 'login',
153+
logout: 'logout',
154+
getUser: 'user',
155+
refreshToken: 'refresh-token',
156+
editUser: 'user',
157+
changePassword: 'user-password'
158+
},
159+
loginWithEmail: true,
160+
loginFieldName: 'email',
161+
loginEditable: true,
162+
loginMinLength: 4,
163+
loginMaxLength: 100,
164+
loginRegex: /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/,
165+
passwordFieldName: 'password',
166+
passwordEditable: true,
167+
passwordMinLength: 1,
168+
passwordMaxLength: 100,
169+
customFields: [
170+
{
171+
name: 'name',
172+
regex: /^.{0,100}$/,
173+
editable: true,
174+
minLength: 0,
175+
maxLength: 100,
176+
required: true
177+
}
178+
]
179+
}
180+
181+
```
182+
183+
Parameters:
184+
- `api` - default: `url` + `path.default` (from **api.js** file) joined fith slash - root url to authentication system API,
185+
- `prefix` - default: `undefined` - next element of auth API url (after `api` property). It may be helpful if authentication system uses the same API as whole application. Then you can set only `url` property in **api.js** file and `prefix` property in **auth.js** file,
186+
- `paths` - default:
187+
```js
188+
{
189+
login: 'login',
190+
logout: 'logout',
191+
getUser: 'user',
192+
refreshToken: 'refresh-token',
193+
editUser: 'user',
194+
changePassword: 'password'
195+
}
196+
```
197+
an object with a list of paths to individual resources. Eg. if `api` equals `https://your-app.com`, `prefix` is `auth`, then path to edit user data will be: 'https://your-app.com/auth/user',
198+
- `loginWithEmail` - default: `true` - information if application have to use e-mail regex for validation,
199+
- `loginFieldName` - default: `'email'` - name of login field needed to communication with API,
200+
- `loginEditable` - default: `true` - information if user can edit his login,
201+
- `loginMinLength` - default: `4` - min length of user's login. Property is needed during login changing,
202+
- `loginMaxLength` - default: `100` - max length of user's login. Property is needed during login changing,
203+
- `loginRegex` - default: `/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/` or `/^[a-zA-Z0-9]+$/` if loginWithEmail property is set to `false` - property needed to new login validation,
204+
- `passwordFieldName` - default: `'password'` - name of password field needed to communication with API,
205+
- `passwordEditable` - default: `true` - information if user can edit his password,
206+
- `passwordMinLength` - default: `8` - min length of user's password. Property is needed during password changing,
207+
- `passwordMaxLength` - default: `100` - max length of user's password. Property is needed during password changing,
208+
- `customFields` - default: `[]` (empty array) - list of other user's fields (except of login and password). These fields will be shown on user's profile form. Properties:
209+
- `name` - default: `undefined` - name of field needed to communication with API,
210+
- `editable` - default: `true` - information if user can modify this field,
211+
- `required` - default: `undefined` - information if field is obligatory,
212+
- `regex` - default: `/^.{0,100}$/`,
213+
- `min` - default: `0` - min length of field. Property is needed during field changing,
214+
- `max` - default: `100` - max length of field. Property is needed during field changing,
141215

142216
### Custom store (Vuex) modules
143217
Create **store-modules.js** file in **src/config** directory. You may use template located in **examples/`example`/config/store-modules.js**. Here you can add your own modules to the Vuex store.
@@ -164,47 +238,30 @@ Copy **examples/`example`/public** folder with the content to your project main
164238
Create **main.js** file in **src** directory. This file should look like that:
165239

166240
```js
167-
import "babel-polyfill" // IE support
168-
import Vue from 'vue' // required
169-
import i18n from './locales/index.js' // required - CRUD always uses i18n
170-
import './plugins/vuetify' // required - Vue CRUD is base on this UI framework
171-
import './plugins/vue-resource' // required - CRUD uses vue-resource
241+
import Vue from 'vue'
242+
import i18n from './locales/index'
243+
import router from './router'
244+
import store from './store'
245+
import http from './plugins/http'
246+
import './plugins/vuetify'
247+
import './plugins/ie'
172248
import './plugins/custom/'
173-
import App from './App.vue' // project's home component - optional
174-
import router from './router' // project's main router - optional
175-
import store from './store' // project's Vuex store - required
176-
import './register-service-worker' // optional
177-
import { api } from './config/api' // required - API config file
249+
import App from './App.vue'
178250
179-
Vue.config.productionTip = false
180-
Vue.http.options.emulateJSON = true;
181-
182-
// API root URL
183-
Vue.http.options.root = api.url + api.path.default
184-
185-
// Interceptor that pushes token to each request (optional, if auth system is used)
186251
Vue.http.interceptors.push((request, next) => {
187252
if (localStorage.getItem('token')) {
188-
request.headers.set('Authorization', 'Bearer ' + localStorage.getItem('token'));
253+
request.headers.set('Authorization', 'Bearer ' + localStorage.getItem('token'))
189254
}
190255
next(response => {
191256
if (response.status === 400 || response.status === 401 || response.status === 403) {
192257
store.commit('auth/logout')
193-
router.push({path: '/login'})
258+
router.push({ path: '/login' })
194259
}
195260
})
196261
})
197262
198-
if ('-ms-scroll-limit' in document.documentElement.style && '-ms-ime-align' in document.documentElement.style) {
199-
window.addEventListener("hashchange", function(event) {
200-
var currentPath = window.location.hash.slice(1);
201-
if (router.path !== currentPath) {
202-
router.push(currentPath)
203-
}
204-
}, false)
205-
}
206-
207263
new Vue({
264+
http,
208265
i18n,
209266
router,
210267
store,

0 commit comments

Comments
 (0)