@moreillon/vue-oidc 0.1.0 → 0.2.0
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 +4 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugins/auth.js +10 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -66,13 +66,15 @@ All refs are read-only.
|
|
|
66
66
|
| Property | Type | Description |
|
|
67
67
|
| -------------- | --------------------------------- | --------------------------------------------------------------------------- |
|
|
68
68
|
| `ready` | `Ref<boolean>` | `true` once initialization has finished (successfully or not) |
|
|
69
|
-
| `error` | `Ref<unknown>` | Error
|
|
70
|
-
| `user` | `Ref<User \| null>` | User info of the authenticated user
|
|
69
|
+
| `error` | `Ref<unknown>` | Error during initialization (e.g. provider unreachable, login cancelled) or when the session could not be renewed. Cleared on the next successful refresh |
|
|
70
|
+
| `user` | `Ref<User \| null>` | User info of the authenticated user. Cleared when the user logs out in another tab or the provider rejects the session |
|
|
71
71
|
| `access_token` | `Ref<string \| null>` | Current access token, kept up to date on refresh |
|
|
72
72
|
| `client` | `Ref<OidcClient \| null>` | Underlying `@moreillon/oidc-auth` client |
|
|
73
73
|
| `login()` | `() => void` | Redirect to the provider's login page |
|
|
74
74
|
| `logout()` | `() => void` | Log out at the provider |
|
|
75
75
|
|
|
76
|
+
`error.value instanceof TokenRejectedError` (exported by this package) tells a session rejected by the provider apart from network or server errors.
|
|
77
|
+
|
|
76
78
|
`useAuth` accepts a type parameter for custom claims: `useAuth<MyUser>()`.
|
|
77
79
|
|
|
78
80
|
The state is shared at module level, so `useAuth()` also works outside components, e.g. in router guards or API clients:
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import auth from "./plugins/auth.js";
|
|
|
2
2
|
import useAuth from "./composables/useAuth.js";
|
|
3
3
|
export { auth, useAuth };
|
|
4
4
|
export type { Options } from "./plugins/auth.js";
|
|
5
|
+
export { TokenRejectedError } from "@moreillon/oidc-auth";
|
|
5
6
|
export type { User, Tokens } from "@moreillon/oidc-auth";
|
package/dist/index.js
CHANGED
package/dist/plugins/auth.js
CHANGED
|
@@ -10,8 +10,18 @@ async function init(options) {
|
|
|
10
10
|
if (oidcData) {
|
|
11
11
|
state.access_token.value = oidcData.tokens.access_token;
|
|
12
12
|
state.user.value = oidcData.user;
|
|
13
|
+
// Also fired when another tab refreshed the tokens
|
|
13
14
|
client.onTokenRefreshed(({ access_token }) => {
|
|
14
15
|
state.access_token.value = access_token;
|
|
16
|
+
state.error.value = null;
|
|
17
|
+
});
|
|
18
|
+
client.onRefreshError((error) => {
|
|
19
|
+
state.error.value = error;
|
|
20
|
+
});
|
|
21
|
+
// Logged out in another tab, or tokens rejected by the provider
|
|
22
|
+
client.onLogout(() => {
|
|
23
|
+
state.user.value = null;
|
|
24
|
+
state.access_token.value = null;
|
|
15
25
|
});
|
|
16
26
|
}
|
|
17
27
|
// When enforced without data, the user is being redirected to the provider
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moreillon/vue-oidc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"vue": "^3.5.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@moreillon/oidc-auth": "^
|
|
24
|
+
"@moreillon/oidc-auth": "^4.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"typescript": "~5.8.0",
|