nuxt-atproto 0.0.2 → 0.0.4
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 +22 -9
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -1
- package/dist/runtime/composables/useAgent.d.ts +8 -0
- package/dist/runtime/composables/useAgent.js +23 -0
- package/dist/runtime/composables/useAtproto.d.ts +8 -0
- package/dist/runtime/composables/useAtproto.js +3 -17
- package/dist/runtime/utils/utilActor.d.ts +2 -0
- package/dist/runtime/utils/utilActor.js +16 -0
- package/package.json +1 -1
- /package/dist/runtime/{plugin.client.d.ts → plugin.d.ts} +0 -0
- /package/dist/runtime/{plugin.client.js → plugin.js} +0 -0
package/README.md
CHANGED
|
@@ -230,27 +230,40 @@ Logs out the currently authenticated user and clears the stored session data.
|
|
|
230
230
|
|
|
231
231
|
<br />
|
|
232
232
|
|
|
233
|
-
###
|
|
233
|
+
### ➡️ isLogged()
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
Indicates whether the user is currently authenticated.
|
|
236
236
|
|
|
237
237
|
```ts
|
|
238
238
|
const atproto = useAtproto()
|
|
239
239
|
|
|
240
|
-
|
|
241
|
-
console.log(
|
|
240
|
+
if (atproto.isLogged()) {
|
|
241
|
+
console.log('User is authenticated')
|
|
242
|
+
} else {
|
|
243
|
+
console.log('User is not logged in')
|
|
244
|
+
}
|
|
245
|
+
```
|
|
242
246
|
|
|
243
|
-
|
|
244
|
-
|
|
247
|
+
**Returns**: Returns a boolean indicating whether the user is authenticated.
|
|
248
|
+
|
|
249
|
+
<br />
|
|
250
|
+
|
|
251
|
+
## 🧩 useAgent(service?: string, fetch?: any)
|
|
252
|
+
|
|
253
|
+
A composable provided by `nuxt-atproto` that offers methods for user authentication and session management, including authenticating, signing out and session restore.
|
|
254
|
+
|
|
255
|
+
```html
|
|
256
|
+
|
|
257
|
+
<script setup lang="ts">
|
|
258
|
+
const agent = useAgent('public')
|
|
259
|
+
</script>
|
|
245
260
|
```
|
|
246
261
|
|
|
247
262
|
**Parameters:**
|
|
248
263
|
|
|
249
|
-
- `service` (optional):
|
|
264
|
+
- `service` (optional): Choose between `public`, `private` or a custom service endpoint.
|
|
250
265
|
- `fetch` (optional): A custom fetch implementation.
|
|
251
266
|
|
|
252
|
-
**Returns:** An object with both public AtpAgent or authenticated account Agent.
|
|
253
|
-
|
|
254
267
|
<br />
|
|
255
268
|
|
|
256
269
|
## License
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -65,7 +65,8 @@ const module = defineNuxtModule({
|
|
|
65
65
|
JSON.stringify(_options.oauth.clientMetadata.local, null, 2)
|
|
66
66
|
);
|
|
67
67
|
addImportsDir(resolve("./runtime/composables"));
|
|
68
|
-
|
|
68
|
+
addImportsDir(resolve("./runtime/utils"));
|
|
69
|
+
addPlugin(resolve("./runtime/plugin"));
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
72
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useNuxtApp, useRuntimeConfig } from "#app";
|
|
2
|
+
import { Agent, AtpAgent } from "@atproto/api";
|
|
3
|
+
export function useAgent(service, fetch) {
|
|
4
|
+
const runtimeConfig = useRuntimeConfig();
|
|
5
|
+
const { $atproto } = useNuxtApp();
|
|
6
|
+
switch (service) {
|
|
7
|
+
case "private":
|
|
8
|
+
if (!$atproto.session.value) {
|
|
9
|
+
throw new Error("Not authenticated");
|
|
10
|
+
}
|
|
11
|
+
return new Agent($atproto.session.value);
|
|
12
|
+
case "public":
|
|
13
|
+
return new AtpAgent({
|
|
14
|
+
service: runtimeConfig.public.atproto.serviceEndpoint.public,
|
|
15
|
+
fetch
|
|
16
|
+
});
|
|
17
|
+
default:
|
|
18
|
+
return new AtpAgent({
|
|
19
|
+
service,
|
|
20
|
+
fetch
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { OAuthSession } from '@atproto/oauth-client';
|
|
2
|
+
export declare function useAtproto(service?: string, fetch?: any): {
|
|
3
|
+
signIn: (serviceEndpoint?: string, options?: any) => Promise<void>;
|
|
4
|
+
signInWithHandle: (handle?: string, options?: any) => Promise<void>;
|
|
5
|
+
signOut: () => Promise<void>;
|
|
6
|
+
restore: (did: string) => Promise<OAuthSession>;
|
|
7
|
+
isLogged: () => any;
|
|
8
|
+
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Agent, AtpAgent } from "@atproto/api";
|
|
2
1
|
import { useRuntimeConfig, useNuxtApp } from "nuxt/app";
|
|
3
|
-
import { reactive } from "vue";
|
|
4
2
|
export function useAtproto(service, fetch) {
|
|
5
3
|
const runtimeConfig = useRuntimeConfig();
|
|
6
4
|
async function signIn(serviceEndpoint = runtimeConfig.public.atproto.serviceEndpoint.private, options = runtimeConfig.public.atproto.oauth.signInOptions) {
|
|
@@ -48,27 +46,15 @@ export function useAtproto(service, fetch) {
|
|
|
48
46
|
console.log("User signed out");
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
|
-
function
|
|
49
|
+
function isLogged() {
|
|
52
50
|
const { $atproto } = useNuxtApp();
|
|
53
|
-
|
|
54
|
-
if (!service2) {
|
|
55
|
-
service2 = runtimeConfig2.public.atproto.serviceEndpoint.public;
|
|
56
|
-
}
|
|
57
|
-
let accountAgent;
|
|
58
|
-
if ($atproto && $atproto.session.value) {
|
|
59
|
-
accountAgent = new Agent($atproto.session.value);
|
|
60
|
-
}
|
|
61
|
-
return reactive({
|
|
62
|
-
public: new AtpAgent({ service: service2, fetch: fetch2 }),
|
|
63
|
-
account: accountAgent
|
|
64
|
-
});
|
|
51
|
+
return $atproto.session.value;
|
|
65
52
|
}
|
|
66
|
-
const agent = useAgent(service, fetch);
|
|
67
53
|
return {
|
|
68
54
|
signIn,
|
|
69
55
|
signInWithHandle,
|
|
70
56
|
signOut,
|
|
71
57
|
restore,
|
|
72
|
-
|
|
58
|
+
isLogged
|
|
73
59
|
};
|
|
74
60
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useAgent } from "../composables/useAgent.js";
|
|
2
|
+
export async function resolveActorDid(handle) {
|
|
3
|
+
const agent = useAgent("public");
|
|
4
|
+
const { did } = await agent.com.atproto.identity.resolveHandle({
|
|
5
|
+
handle
|
|
6
|
+
}).then((result) => result.data);
|
|
7
|
+
return did;
|
|
8
|
+
}
|
|
9
|
+
export async function resolveActorServiceEndpoint(did) {
|
|
10
|
+
const response = await fetch(`https://plc.directory/${did}`);
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
throw new Error("Failed to fetch profile service endpoint");
|
|
13
|
+
}
|
|
14
|
+
const data = await response.json();
|
|
15
|
+
return data.service[0].serviceEndpoint;
|
|
16
|
+
}
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|