-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance(client): /authおよびMiAuthのUIをブラッシュアップ
Fix #9742
- Loading branch information
Showing
5 changed files
with
208 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,66 @@ | ||
<template> | ||
<section class=""> | ||
<div class="">{{ $t('_auth.shareAccess', { name: app.name }) }}</div> | ||
<div class=""> | ||
<h2>{{ app.name }}</h2> | ||
<p class="id">{{ app.id }}</p> | ||
<p class="description">{{ app.description }}</p> | ||
</div> | ||
<div class=""> | ||
<h2>{{ $ts._auth.permissionAsk }}</h2> | ||
<ul> | ||
<li v-for="p in app.permission" :key="p">{{ $t(`_permissions.${p}`) }}</li> | ||
</ul> | ||
</div> | ||
<div class=""> | ||
<MkButton inline @click="cancel">{{ $ts.cancel }}</MkButton> | ||
<MkButton inline primary @click="accept">{{ $ts.accept }}</MkButton> | ||
</div> | ||
</section> | ||
<section> | ||
<div v-if="app.permission.length > 0"> | ||
<p>{{ i18n.ts._auth.permissionAsk }}</p> | ||
<ul> | ||
<li v-for="p in app.permission" :key="p">{{ $t(`_permissions.${p}`) }}</li> | ||
</ul> | ||
</div> | ||
<div>{{ i18n.t('_auth.shareAccess', { name: `${name} (${app.id})` }) }}</div> | ||
<div :class="$style.buttons"> | ||
<MkButton inline @click="cancel">{{ i18n.ts.cancel }}</MkButton> | ||
<MkButton inline primary @click="accept">{{ i18n.ts.accept }}</MkButton> | ||
</div> | ||
</section> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
<script lang="ts" setup> | ||
import { } from 'vue'; | ||
import MkButton from '@/components/MkButton.vue'; | ||
import * as os from '@/os'; | ||
import { i18n } from '@/i18n'; | ||
import { AuthSession } from 'misskey-js/built/entities'; | ||
export default defineComponent({ | ||
components: { | ||
MkButton, | ||
}, | ||
props: ['session'], | ||
computed: { | ||
name(): string { | ||
const el = document.createElement('div'); | ||
el.textContent = this.app.name; | ||
return el.innerHTML; | ||
}, | ||
app(): any { | ||
return this.session.app; | ||
}, | ||
}, | ||
methods: { | ||
cancel() { | ||
os.api('auth/deny', { | ||
token: this.session.token, | ||
}).then(() => { | ||
this.$emit('denied'); | ||
}); | ||
}, | ||
accept() { | ||
os.api('auth/accept', { | ||
token: this.session.token, | ||
}).then(() => { | ||
this.$emit('accepted'); | ||
}); | ||
}, | ||
}, | ||
const props = defineProps<{ | ||
session: AuthSession; | ||
}>(); | ||
const emit = defineEmits<{ | ||
(event: 'accepted'): void; | ||
(event: 'denied'): void; | ||
}>(); | ||
const app = $computed(() => props.session.app); | ||
const name = $computed(() => { | ||
const el = document.createElement('div'); | ||
el.textContent = app.name; | ||
return el.innerHTML; | ||
}); | ||
function cancel() { | ||
os.api('auth/deny', { | ||
token: props.session.token, | ||
}).then(() => { | ||
emit('denied'); | ||
}); | ||
} | ||
function accept() { | ||
os.api('auth/accept', { | ||
token: props.session.token, | ||
}).then(() => { | ||
emit('accepted'); | ||
}); | ||
} | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.buttons { | ||
margin-top: 16px; | ||
display: flex; | ||
gap: 8px; | ||
flex-wrap: wrap; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,105 @@ | ||
<template> | ||
<div v-if="$i && fetching" class=""> | ||
<MkLoading/> | ||
</div> | ||
<div v-else-if="$i"> | ||
<XForm | ||
v-if="state == 'waiting'" | ||
ref="form" | ||
class="form" | ||
:session="session" | ||
@denied="state = 'denied'" | ||
@accepted="accepted" | ||
/> | ||
<div v-if="state == 'denied'" class="denied"> | ||
<h1>{{ $ts._auth.denied }}</h1> | ||
</div> | ||
<div v-if="state == 'accepted'" class="accepted"> | ||
<h1>{{ session.app.isAuthorized ? $t('already-authorized') : $ts.allowed }}</h1> | ||
<p v-if="session.app.callbackUrl">{{ $ts._auth.callback }}<MkEllipsis/></p> | ||
<p v-if="!session.app.callbackUrl">{{ $ts._auth.pleaseGoBack }}</p> | ||
</div> | ||
<div v-if="state == 'fetch-session-error'" class="error"> | ||
<p>{{ $ts.somethingHappened }}</p> | ||
</div> | ||
</div> | ||
<div v-else class="signin"> | ||
<MkSignin @login="onLogin"/> | ||
</div> | ||
<MkStickyContainer> | ||
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs" /></template> | ||
<MkSpacer :content-max="500"> | ||
<div v-if="state == 'fetch-session-error'"> | ||
<p>{{ i18n.ts.somethingHappened }}</p> | ||
</div> | ||
<div v-else-if="$i && !session"> | ||
<MkLoading /> | ||
</div> | ||
<div v-else-if="$i && session"> | ||
<XForm | ||
v-if="state == 'waiting'" | ||
class="form" | ||
:session="session" | ||
@denied="state = 'denied'" | ||
@accepted="accepted" | ||
/> | ||
<div v-if="state == 'denied'"> | ||
<h1>{{ i18n.ts._auth.denied }}</h1> | ||
</div> | ||
<div v-if="state == 'accepted' && session"> | ||
<h1>{{ session.app.isAuthorized ? $t('already-authorized') : i18n.ts.allowed }}</h1> | ||
<p v-if="session.app.callbackUrl">{{ i18n.ts._auth.callback }} | ||
<MkEllipsis /> | ||
</p> | ||
<p v-if="!session.app.callbackUrl">{{ i18n.ts._auth.pleaseGoBack }}</p> | ||
</div> | ||
</div> | ||
<div v-else> | ||
<p :class="$style.loginMessage">{{ i18n.ts._auth.pleaseLogin }}</p> | ||
<MkSignin @login="onLogin" /> | ||
</div> | ||
</MkSpacer> | ||
</MkStickyContainer> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
<script lang="ts" setup> | ||
import { onMounted } from 'vue'; | ||
import XForm from './auth.form.vue'; | ||
import MkSignin from '@/components/MkSignin.vue'; | ||
import * as os from '@/os'; | ||
import { login } from '@/account'; | ||
import { $i, login } from '@/account'; | ||
import { definePageMetadata } from '@/scripts/page-metadata'; | ||
import { AuthSession } from 'misskey-js/built/entities'; | ||
import { i18n } from '@/i18n'; | ||
export default defineComponent({ | ||
components: { | ||
XForm, | ||
MkSignin, | ||
}, | ||
props: ['token'], | ||
data() { | ||
return { | ||
state: null, | ||
session: null, | ||
fetching: true, | ||
}; | ||
}, | ||
mounted() { | ||
if (!this.$i) return; | ||
const props = defineProps<{ | ||
token: string; | ||
}>(); | ||
// Fetch session | ||
os.api('auth/session/show', { | ||
token: this.token, | ||
}).then(session => { | ||
this.session = session; | ||
this.fetching = false; | ||
let state = $ref<'waiting' | 'accepted' | 'fetch-session-error' | 'denied' | null>(null); | ||
let session = $ref<AuthSession | null>(null); | ||
// 既に連携していた場合 | ||
if (this.session.app.isAuthorized) { | ||
os.api('auth/accept', { | ||
token: this.session.token, | ||
}).then(() => { | ||
this.accepted(); | ||
}); | ||
} else { | ||
this.state = 'waiting'; | ||
} | ||
}).catch(error => { | ||
this.state = 'fetch-session-error'; | ||
this.fetching = false; | ||
function accepted() { | ||
state = 'accepted'; | ||
if (session && session.app.callbackUrl) { | ||
const url = new URL(session.app.callbackUrl); | ||
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw new Error('invalid url'); | ||
location.href = `${session.app.callbackUrl}?token=${session.token}`; | ||
} | ||
} | ||
function onLogin(res) { | ||
login(res.i); | ||
} | ||
onMounted(async () => { | ||
if (!$i) return; | ||
try { | ||
session = await os.api('auth/session/show', { | ||
token: props.token, | ||
}); | ||
}, | ||
methods: { | ||
accepted() { | ||
this.state = 'accepted'; | ||
if (this.session.app.callbackUrl) { | ||
const url = new URL(this.session.app.callbackUrl); | ||
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw new Error('invalid url'); | ||
location.href = `${this.session.app.callbackUrl}?token=${this.session.token}`; | ||
} | ||
}, onLogin(res) { | ||
login(res.i); | ||
}, | ||
}, | ||
// 既に連携していた場合 | ||
if (session.app.isAuthorized) { | ||
await os.api('auth/accept', { | ||
token: session.token, | ||
}); | ||
accepted(); | ||
} else { | ||
state = 'waiting'; | ||
} | ||
} catch (e) { | ||
state = 'fetch-session-error'; | ||
} | ||
}); | ||
</script> | ||
<style lang="scss" scoped> | ||
const headerActions = $computed(() => []); | ||
const headerTabs = $computed(() => []); | ||
definePageMetadata({ | ||
title: i18n.ts._auth.shareAccessTitle, | ||
icon: 'ti ti-apps', | ||
}); | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.loginMessage { | ||
text-align: center; | ||
margin: 8px 0 24px; | ||
} | ||
</style> |
Oops, something went wrong.