@logto/vue 0.1.13 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # Logto Vue SDK
2
+ [![Version](https://img.shields.io/npm/v/@logto/vue)](https://www.npmjs.com/package/@logto/vue)
3
+ [![Build Status](https://github.com/logto-io/js/actions/workflows/main.yml/badge.svg)](https://github.com/logto-io/js/actions/workflows/main.yml)
4
+ [![Codecov](https://img.shields.io/codecov/c/github/logto-io/js)](https://app.codecov.io/gh/logto-io/js?branch=master)
5
+
6
+ The Logto Vue SDK written in TypeScript. Check out our [integration guide](https://docs.logto.io/integrate-sdk/vue) or [docs](https://docs.logto.io/sdk/vue) for more information.
7
+
8
+ We also provide [集成指南](https://docs.logto.io/zh-cn/integrate-sdk/vue) and [文档](https://docs.logto.io/zh-cn/sdk/vue) in Simplified Chinese.
9
+
10
+ ## Installation
11
+
12
+ ### Using npm
13
+
14
+ ```bash
15
+ npm install @logto/vue
16
+ ```
17
+
18
+ ### Using yarn
19
+
20
+ ```bash
21
+ yarn add @logto/vue
22
+ ```
23
+
24
+ ### Using pnpm
25
+
26
+ ```bash
27
+ pnpm install @logto/vue
28
+ ```
29
+
30
+ ### Using CDN
31
+
32
+ ```bash
33
+ <script src="https://logto.io/js/logto-sdk-vue/0.1.0/logto-sdk-vue.production.js" />
34
+ ```
35
+
36
+ ## Get Started
37
+
38
+ A sample project with the following code snippets can be found at [Vue Sample](https://github.com/logto-io/js/tree/master/packages/vue-sample)
39
+
40
+ Check out the source code and try it yourself. (We use [pnpm](https://pnpm.io/) for package management)
41
+
42
+ ```bash
43
+ pnpm i && pnpm start
44
+ ```
45
+
46
+ ### Import Logto Vue plugin
47
+
48
+ ```ts
49
+ import { createLogto, LogtoConfig } from '@logto/vue';
50
+
51
+ const config: LogtoConfig = {
52
+ appId: '<your-application-id>',
53
+ endpoint: '<your-logto-endpoint>'
54
+ };
55
+
56
+ const app = createApp(App);
57
+
58
+ app.use(createLogto, config);
59
+ app.mount("#app");
60
+ ```
61
+
62
+ ### Setup your sign-in
63
+
64
+ ```ts
65
+ import { useLogto } from "@logto/vue";
66
+
67
+ const { signIn } = useLogto();
68
+ const onClickSignIn = () => signIn(redirectUrl);
69
+ ```
70
+
71
+ ```html
72
+ <button @click="onClickSignIn">Sign In</button>
73
+ ```
74
+
75
+ ### Retrieve Auth Status
76
+
77
+ ```ts
78
+ import { useLogto } from '@logto/vue';
79
+
80
+ const { isAuthenticated } = useLogto();
81
+ ```
82
+
83
+ ```html
84
+ <div v-if="!isAuthenticated">
85
+ <!-- E.g. navigate to the sign in page -->
86
+ </div>
87
+ <div v-else>
88
+ <!-- Do things when user is authenticated -->
89
+ </div>
90
+ ```
91
+
92
+ ### Sign out
93
+
94
+ ```ts
95
+ import { useLogto } from "@logto/vue";
96
+
97
+ const { signOut } = useLogto();
98
+ const onClickSignOut = () => signOut('http://localhost:1234');
99
+ ```
100
+
101
+ ```html
102
+ <button @click="onClickSignOut">Sign Out</button>
103
+ ```
104
+
105
+ ## Resources
106
+
107
+ [![Website](https://img.shields.io/badge/website-logto.io-8262F8.svg)](https://logto.io/)
108
+ [![Docs](https://img.shields.io/badge/docs-logto.io-green.svg)](https://docs.logto.io/docs/sdk/swift/)
109
+ [![Discord](https://img.shields.io/discord/965845662535147551?logo=discord&logoColor=ffffff&color=7389D8&cacheSeconds=600)](https://discord.gg/UEPaF3j5e6)
package/lib/index.d.ts CHANGED
@@ -73,7 +73,7 @@ export declare const useLogto: () => Logto;
73
73
  *
74
74
  * Use this in the setup script of your Callback page to make sure the injection works
75
75
  */
76
- export declare const useHandleSignInCallback: (returnToPageUrl?: string) => {
76
+ export declare const useHandleSignInCallback: (callback?: (() => void) | undefined) => {
77
77
  isLoading: Readonly<Ref<boolean>>;
78
78
  isAuthenticated: Readonly<Ref<boolean>>;
79
79
  error: Readonly<Ref<Error | undefined>>;
package/lib/index.js CHANGED
@@ -92,17 +92,17 @@ exports.useLogto = useLogto;
92
92
  *
93
93
  * Use this in the setup script of your Callback page to make sure the injection works
94
94
  */
95
- const useHandleSignInCallback = (returnToPageUrl = window.location.origin) => {
95
+ const useHandleSignInCallback = (callback) => {
96
96
  const context = (0, vue_1.inject)(consts_1.contextInjectionKey);
97
97
  if (!context) {
98
98
  return (0, context_1.throwContextError)();
99
99
  }
100
- const currentPageUrl = window.location.href;
101
100
  const { isAuthenticated, isLoading, logtoClient, error } = context;
102
101
  const { handleSignInCallback } = (0, plugin_1.createPluginMethods)(context);
103
102
  (0, vue_1.watchEffect)(() => {
103
+ const currentPageUrl = window.location.href;
104
104
  if (!isAuthenticated.value && logtoClient.value?.isSignInRedirected(currentPageUrl)) {
105
- void handleSignInCallback(currentPageUrl, returnToPageUrl);
105
+ void handleSignInCallback(currentPageUrl, callback);
106
106
  }
107
107
  });
108
108
  return {
package/lib/plugin.d.ts CHANGED
@@ -12,5 +12,5 @@ export declare const createPluginMethods: (context: Context) => {
12
12
  iat: number;
13
13
  at_hash?: string | undefined;
14
14
  } | undefined;
15
- handleSignInCallback: (callbackUri: string, returnToPageUrl: string) => Promise<undefined>;
15
+ handleSignInCallback: (callbackUri: string, callbackFunction?: (() => void) | undefined) => Promise<undefined>;
16
16
  };
package/lib/plugin.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPluginMethods = void 0;
4
4
  const context_1 = require("./context");
5
5
  const createPluginMethods = (context) => {
6
- const { logtoClient, setLoading, setError } = context;
6
+ const { logtoClient, setLoading, setError, setIsAuthenticated } = context;
7
7
  const signIn = async (redirectUri) => {
8
8
  if (!logtoClient.value) {
9
9
  return (0, context_1.throwContextError)();
@@ -78,17 +78,15 @@ const createPluginMethods = (context) => {
78
78
  setError(error, 'Unexpected error occurred while getting id token claims.');
79
79
  }
80
80
  };
81
- const handleSignInCallback = async (callbackUri, returnToPageUrl) => {
81
+ const handleSignInCallback = async (callbackUri, callbackFunction) => {
82
82
  if (!logtoClient.value) {
83
83
  return (0, context_1.throwContextError)();
84
84
  }
85
85
  try {
86
86
  setLoading(true);
87
87
  await logtoClient.value.handleSignInCallback(callbackUri);
88
- // We deliberately do NOT set isAuthenticated to true here, because the app state may change immediately
89
- // even before navigating to the return page URL, which might cause rendering problems.
90
- // Moreover, since the location will be redirected, the isAuthenticated state will not matter any more.
91
- window.location.assign(returnToPageUrl);
88
+ setIsAuthenticated(true);
89
+ callbackFunction?.();
92
90
  }
93
91
  catch (error) {
94
92
  setError(error, 'Unexpected error occurred while handling sign in callback.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/vue",
3
- "version": "0.1.13",
3
+ "version": "0.1.16",
4
4
  "main": "./lib/index.js",
5
5
  "exports": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
@@ -15,7 +15,6 @@
15
15
  },
16
16
  "scripts": {
17
17
  "dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
18
- "preinstall": "npx only-allow pnpm",
19
18
  "precommit": "lint-staged",
20
19
  "build": "rm -rf lib/ && tsc -p tsconfig.build.json",
21
20
  "lint": "eslint --ext .ts src",
@@ -24,7 +23,7 @@
24
23
  "prepack": "pnpm test"
25
24
  },
26
25
  "dependencies": {
27
- "@logto/browser": "^0.1.11"
26
+ "@logto/browser": "^0.1.16"
28
27
  },
29
28
  "devDependencies": {
30
29
  "@jest/types": "^27.5.1",
@@ -33,7 +32,7 @@
33
32
  "@types/jest": "^27.4.1",
34
33
  "eslint": "^8.9.0",
35
34
  "jest": "^27.5.1",
36
- "lint-staged": "^12.3.4",
35
+ "lint-staged": "^13.0.0",
37
36
  "postcss": "^8.4.6",
38
37
  "prettier": "^2.5.1",
39
38
  "stylelint": "^14.8.2",
@@ -61,5 +60,5 @@
61
60
  "publishConfig": {
62
61
  "access": "public"
63
62
  },
64
- "gitHead": "8f8934f949e71573d9e06a8595826fcc8fb426e2"
63
+ "gitHead": "b56e794cea7ba791c73cd2da6e4ea405223d6970"
65
64
  }