1.1.8 • Published 1 year ago

@solanyan/nuxt-auth-client v1.1.8

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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)

SCHEME

  1. 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
  • 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
  1. AZURE_AD
  • Description:
    • scheme for azure ad (Under development).
    • Using MASL.js(v2)
    • Please check code if you want to use this scheme.
  1. ANONYMOUS
  • Provide methods:
    • No method provided
      • router guard only

Install

  • Run npm install @solanyan/nuxt-auth-client
  • Add modules @solanyan/nuxt-auth-client and config auth_client to nuxt.config.ts
  • Make sure set ssr: false to nuxt.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

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago