@solanyan/nuxt-auth-client
v1.1.8
Published
Not tested to work well. This module not recomended for production use.
Downloads
4
Readme
NOTICE
Not tested to work well. This module not recomended for production use.
FEATURE
- Authentication client for SPA (static site).
- No dependency server, just add client plugin and routeMiddleware.
- Provide
auth
(useNuxtApp().$auth)
- Provide
SCHEME
- COOKIE
- Provide methods:
- do login
- $auth.login(username: string, password: string, loginCallback?: LoginCallBack): boolean
- type LoginCallback = (success: boolean) => false | void
- if return false, skip default navigate process
- do logout
- $auth.logout(logoutCallback?: LogoutCallBack): boolean
- type LogoutCallback = () => false | void
- if return false, skip default navigate process
- do check login status
- $auth.isLoggedIn(): boolean
- do login
- Description:
- username and password credential login with CSRF token
- assumed to be used with Spring(Boot) Framework
- more details please check out source code.
- API requrement:
- login api return status code if sucess = 200, failure = 401
- sync api return body just boolean if user logged in = true, not logged in = false
- Use for initial access cheking login status and update CSRF with http header
- AZURE_AD
- Description:
- scheme for azure ad (Under development).
- Using MASL.js(v2)
- Please check code if you want to use this scheme.
- ANONYMOUS
- Provide methods:
- No method provided
- router guard only
- No method provided
Install
- Run
npm install @solanyan/nuxt-auth-client
- Add modules
@solanyan/nuxt-auth-client
and configauth_client
tonuxt.config.ts
- Make sure set
ssr: false
tonuxt.config.ts
- No support SSR (may be cause errors)
Default Config
auth_client: {
SCHEME: 'COOKIE', # 'COOKIE' or 'ANONYMOUS'
SCHEME_CONFIG: {
COOKIE: {
API: {
BASE_URL: '',
CREDENTIALS: 'same-origin',
POST_FORM: false,
ENDPOINTS: {
LOGIN: {
PATH: '/api/auth/login',
PROPERTY: {
USERNAME: 'username',
PASSWORD: 'password'
}
},
LOGOUT: {
PATH: '/api/auth/logout'
},
SYNC: {
PATH: '/api/auth/sync'
}
},
},
CSRF: {
ENABLE: true,
HEADER_NAME: 'X-XSRF-TOKEN',
COOKIE_KEY: 'XSRF-TOKEN'
},
DEV_MODE: {
ENABLE: false,
BASE_URL: 'https://localhost:8443/',
CREDENTIALS: 'include'
}
},
AZURE_AD: {
MSAL: {
CLIENT_ID: 'your client id',
TENANT_ID: 'your tenant id',
REDIRECT_URL: 'redirect url',
USE_POPUP_API: false,
SCOPES: ['User.Read']
}
}
ANONYMOUS: undefined
},
PAGE_PATH: {
LOGIN: '/login',
LOGIN_TO: '/auth/home',
LOGOUT_TO: '/'
},
ROUTER_GUARD_PATHES: ['/auth']
}
Development
- Run
npm run dev:prepare
to generate type stubs. - Use
npm run dev
to start playground in development mode.
Licence
MIT License © 2022 Sola-nyan