AT Protocol module for Open Web Desktop
1import { useAtprotoAccountStore } from './stores/storeAtprotoAccount'
2import { defineNuxtPlugin } from 'nuxt/app'
3import { useAtproto, useAgent } from '#imports'
4
5export default defineNuxtPlugin({
6 name: 'owd-plugin-atproto',
7 parallel: true,
8 async setup(nuxtApp) {
9 const atprotoAccountStore = useAtprotoAccountStore()
10 // handle oauth callback + session restore
11
12 nuxtApp.hook('app:mounted', async () => {
13 const {$atproto} = useNuxtApp()
14 const atproto = useAtproto()
15
16 if (atproto.isLogged()) {
17 const agent = useAgent('public')
18
19 atprotoAccountStore.setAccountState('fetching', true)
20
21 await agent
22 .getProfile({
23 actor: $atproto.session.value.sub,
24 })
25 .then((profile) => {
26 atprotoAccountStore.setAccount(profile.data)
27 })
28 }
29 })
30 },
31})