npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

authorizer-vue-ts

v1.0.9

Published

authorizer vue sdk

Downloads

8

Readme

authorizer-vue

Authorizer Vue SDK allows you to implement authentication in your Vue application quickly. It also allows you to access the user profile.

Here is a quick guide on getting started with @authorizerdev/authorizer-vue package.

Code Sandbox Demo: https://codesandbox.io/s/authorizer-vue-example-700l1h

Step 1 - Create Instance

Get Authorizer URL by instantiating Authorizer instance and configuring it with necessary environment variables.

Step 2 - Install package

Install @authorizerdev/authorizer-vue library

npm i --save @authorizerdev/authorizer-vue
OR
yarn add @authorizerdev/authorizer-vue

Step 3 - Configure Provider and use Authorizer Components

Authorizer comes with a Provider component that exposes a composable function to return a reactive context to it's children by using the useAuthorizer injection key, internally toRefs are used when returning the reactive state so that the consuming component(s) can destructure/spread the returned object without losing reactivity and each property could be watched to perform actions accordingly.

<template>
	<div :style="{ display: 'flex', justifyContent: 'center' }">
		<authorizer-provider
			:config="{
				authorizerURL: 'http://localhost:8080',
				redirectURL: window.location.origin,
				clientID: 'AUTHORIZER_CLIENT_ID'
			}"
			:onStateChangeCallback="stateChangeCallback"
		>
			<router-view />
		</authorizer-provider>
	</div>
</template>

<script lang="ts">
import { AuthorizerProvider, type AuthorizerState } from '@authorizerdev/authorizer-vue';

export default {
	components: {
		'authorizer-provider': AuthorizerProvider
	},
	setup() {
		const stateChangeCallback = (state: AuthorizerState) => {
			console.log('state changed ==>> ', state);
		};
		return {
			stateChangeCallback,
			window
		};
	}
};
</script>
<template>
	<div>
		<h1 :style="{ textAlign: 'center' }">Welcome to Authorizer</h1>
		<br />
		<authorizer-root :onLogin="onLogin" />
	</div>
</template>

<script lang="ts">
import { AuthorizerRoot, type AuthorizerContextOutputType } from '@authorizerdev/authorizer-vue';
import { inject, watch } from 'vue';
import { useRouter } from 'vue-router';
export default {
	name: 'Login',
	components: {
		'authorizer-root': AuthorizerRoot
	},
	setup() {
		const useAuthorizer = inject('useAuthorizer') as () => AuthorizerContextOutputType;
		const { token, config } = useAuthorizer?.();
		const router = useRouter();
		const onLogin = () => {
			console.log('test login');
		};
		watch(
			token,
			(newvalue) => {
				if (newvalue) {
					console.log('access token ==>> ', token?.value?.access_token);
					router.push('/dashboard');
				}
			},
			{
				immediate: true
			}
		);
		config &&
			watch(config.is_basic_authentication_enabled, (newvalue, oldvalue) => {
				console.log('basic auth enabled (old value) ==>> ', oldvalue);
				console.log('basic auth enabled (new value) ==>> ', newvalue);
			});
		return {
			onLogin
		};
	}
};
</script>

Commands

Local Development

The recommended workflow is to run authorizer in one terminal:

npm run dev # or yarn dev

This starts a local dev-server with a sandbox environment.

npm run build # or yarn build

This uses Vite to build the project files to /dist and call build:types script.

npm run build:types # or yarn build:types

This generates TypeScript declaration files for our .vue files (using vue-tsc).

npm run typecheck # or yarn typecheck

This runs a typecheck against our Vue components to make sure there are no type errors (using vue-tsc).

Configuration

Typescript:

  • Root tsconfig: tsconfig.json contains a reference to all the others tsconfig files.
  • Components tsconfig: tsconfig.app.json will take care of compiling our Vue components inside src/.
  • Build-types tsconfig: tsconfig.build-types.json will take care of generating the proper types declaration files of our Vue components inside src/.
  • Tools tsconfig: tsconfig.config.json will take care of all our tooling configuration files (we only have vite at the moment).

Vite:

  • Vite requires a configuration to compile and bundle .vue to .js files that can be consumed through an npm module. It uses rollup.js under the hood, check out the comments in vite.config.ts file in the project root to learn more about the configuarition details.

Eslint:

  • All required linting configurations are specified in the .elsintrc.json file in the project root, check the comments in each section to learn more about the configuarition details.

Prettier:

  • We have the "usePrettierrc" option set to true in the eslint configuration file which tells the prettier-vue plugin to use the Prettier configuration file .prettierrc in the project root directory and override any default settings.

Husky:

  • A pre-commit hook is set in .husky/pre-commit which formats the code and checks for any linting errors.