elk/pages/login.vue

55 lines
1.3 KiB
Vue
Raw Normal View History

2022-11-14 15:54:30 +01:00
<script setup lang="ts">
2022-11-15 12:54:07 +01:00
import { login } from 'masto'
import { DEFAULT_SERVER } from '~/plugins/masto'
2022-11-14 15:54:30 +01:00
const server = useCookie('nuxtodon-server')
const token = useCookie('nuxtodon-token')
2022-11-15 12:54:07 +01:00
async function oauth() {
const client = await login({
url: `https://${server.value || DEFAULT_SERVER}`,
})
const redirectUri = `${location.origin}/api/${server.value || DEFAULT_SERVER}/oauth`
const app = await client.apps.create({
clientName: 'Nuxtodon',
redirectUris: redirectUri,
scopes: 'read write follow push',
})
console.log({ app })
const url = `https://${server.value || DEFAULT_SERVER}/oauth/authorize
?client_id=${app.clientId}
&scope=read+write+follow+push
&redirect_uri=${encodeURIComponent(redirectUri)}
&response_type=code`.replace(/\n/g, '')
const a = document.createElement('a')
a.href = url
a.target = '_blank'
a.click()
}
2022-11-14 15:54:30 +01:00
</script>
<template>
<div p4>
2022-11-15 12:54:07 +01:00
<button @click="oauth()">
OAuth
</button>
2022-11-14 15:54:30 +01:00
<input
v-model="server"
placeholder="Server URL"
bg-transparent text-current
border="~ border" p="x2 y1" w-full
outline-none
>
<input
v-model="token"
placeholder="Token"
bg-transparent text-current
border="~ border" p="x2 y1" w-full
outline-none
>
</div>
</template>