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

@oneauth/sdk-vue-next

v0.0.3

Published

需搭配@oneauth/sdk-core 使用

Downloads

15

Readme

@oneauth/sdk-vue-next

需搭配@oneauth/sdk-core 使用

安装

除了本 sdk,也需要安装@oneauth/sdk-core

npm i --save @oneauth/sdk-core @oneauth/sdk-vue-next

实例化@oneauth/sdk-core

在使用@oneauth/sdk-vue-next 之前,需要初始化@oneauth/sdk-core, 查看教程

开始使用@oneauth/sdk-vue-next

@oneauth/sdk-vue-next 提供了一个登录重定向的页面,和一个用于鉴权的导航守卫

你需要把登录重定向页面配置到路由当中。

并在需要鉴权的路由的 meta 上添加 auth 参数

  1. 实例化@oneauth/sdk-core 和@oneauth/sdk-vue-next
import App from "./App.vue";
import router from "./router";

import OneAuth from "@oneauth/sdk-core";
import OneAuthVue from "@oneauth/sdk-vue-next";
const oneAuth = new OneAuth({
  issuer: `kang.oneauth.cn/oauth/v1`,
  clientId: `2YXXZ78611K0c8906MX6RJ8c0s84VcQB`,
  redirectUri: `http://localhost:8080/callback`,
  scopes: ["openid", "profile", "email"],
});
  1. 注入$oneauth

    把 @oneauth/sdk-core 实例注入到 Vue 的原型上

createApp(App).use(OneAuthVue, {
  oneAuth,
});
  1. 添加登录按钮

在页面中添加一个按钮,并对其调用

this.$oneauth.login();
<template>
  <button @click="login">login</button>
</template>
<script lang="ts">
  import { defineComponent } from "vue";

  export default defineComponent({
    name: "App",

    methods: {
      login() {
        this.$oneAuth.login();
      },
    },
  });
</script>
  1. 添加登录重定向页面

从@oneauth/sdk-vue-next 得到登录重定向页面,并配置到路由中。

路由的路径需要与@oneauth/sdk-core 的实例化参数redirectUri一致。

import { LoginCallback } from "@oneauth/sdk-vue-next";

const routes: Array<RouteConfig> = [
  {
    path: "/callback",
    component: LoginCallback,
  },
];
  1. 添加路由鉴权和导航守卫

从@oneauth/sdk-vue-next 中获取导航守卫navigationGuard,并配置到路由中。

在需要鉴权的路由的 meta 中配置 auth 属性

这样,在打开该路由时都会检查是否登录了。

如果没有登录则会跳转到登录页。

登录完成后会跳转回来。

import { LoginCallback, navigationGuard } from "@oneauth/sdk-vue-next";

const routes: Array<RouteConfig> = [
  {
    path: "/callback",
    component: LoginCallback,
  },
  {
    path: "/about",
    name: "About",
    meta: {
      auth: true,
    },
    component: () => import("../views/About.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach(navigationGuard);

export default router;