From 073c3ccc777945700e9c9e0560c728e7fce2df59 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:24:20 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix(frontend):=20=E3=83=A6=E3=83=BC?= =?UTF-8?q?=E3=82=B6=E3=83=BC=E7=99=BB=E9=8C=B2=E5=AE=8C=E4=BA=86=E6=99=82?= =?UTF-8?q?=E3=81=AB=E3=82=B5=E3=82=A4=E3=83=B3=E3=82=A4=E3=83=B3API?= =?UTF-8?q?=E3=82=92=E5=88=A5=E9=80=94=E4=BD=BF=E7=94=A8=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/MkSignupDialog.form.vue | 84 +++++++++++-------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/packages/frontend/src/components/MkSignupDialog.form.vue b/packages/frontend/src/components/MkSignupDialog.form.vue index ff096dc7294d..1ab45c83edb5 100644 --- a/packages/frontend/src/components/MkSignupDialog.form.vue +++ b/packages/frontend/src/components/MkSignupDialog.form.vue @@ -98,7 +98,7 @@ const props = withDefaults(defineProps<{ }); const emit = defineEmits<{ - (ev: 'signup', user: Misskey.entities.SigninFlowResponse): void; + (ev: 'signup', user: Misskey.entities.SignupResponse): void; (ev: 'signupEmailPending'): void; }>(); @@ -250,18 +250,30 @@ async function onSubmit(): Promise { if (submitting.value) return; submitting.value = true; - try { - await misskeyApi('signup', { - username: username.value, - password: password.value, - emailAddress: email.value, - invitationCode: invitationCode.value, - 'hcaptcha-response': hCaptchaResponse.value, - 'm-captcha-response': mCaptchaResponse.value, - 'g-recaptcha-response': reCaptchaResponse.value, - 'turnstile-response': turnstileResponse.value, - }); - if (instance.emailRequiredForSignup) { + const signupPayload: Misskey.entities.SignupRequest = { + username: username.value, + password: password.value, + emailAddress: email.value, + invitationCode: invitationCode.value, + 'hcaptcha-response': hCaptchaResponse.value, + 'm-captcha-response': mCaptchaResponse.value, + 'g-recaptcha-response': reCaptchaResponse.value, + 'turnstile-response': turnstileResponse.value, + }; + + const res = await fetch(`${config.apiUrl}/signup`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(signupPayload), + }).catch(() => { + onSignupApiError(); + return null; + }); + + if (res) { + if (res.status === 204 || instance.emailRequiredForSignup) { os.alert({ type: 'success', title: i18n.ts._signup.almostThere, @@ -269,33 +281,31 @@ async function onSubmit(): Promise { }); emit('signupEmailPending'); } else { - const res = await misskeyApi('signin-flow', { - username: username.value, - password: password.value, - }); - emit('signup', res); - - if (props.autoSet && res.finished) { - return login(res.i); - } else { - os.alert({ - type: 'error', - text: i18n.ts.somethingHappened, - }); + const resJson = (await res.json()) as Misskey.entities.SignupResponse; + if (_DEV_) console.log(resJson); + + emit('signup', resJson); + + if (props.autoSet) { + await login(resJson.token); } } - } catch { - submitting.value = false; - hcaptcha.value?.reset?.(); - mcaptcha.value?.reset?.(); - recaptcha.value?.reset?.(); - turnstile.value?.reset?.(); - - os.alert({ - type: 'error', - text: i18n.ts.somethingHappened, - }); } + + submitting.value = false; +} + +function onSignupApiError() { + submitting.value = false; + hcaptcha.value?.reset?.(); + mcaptcha.value?.reset?.(); + recaptcha.value?.reset?.(); + turnstile.value?.reset?.(); + + os.alert({ + type: 'error', + text: i18n.ts.somethingHappened, + }); } From dd7f8b3d4c40abf5b2e61d077b1b01bc0c8a9967 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:38:00 +0900 Subject: [PATCH 2/3] =?UTF-8?q?emit=E3=81=95=E3=82=8C=E3=82=8B=E3=82=AA?= =?UTF-8?q?=E3=83=96=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88=E3=81=AE=E5=9E=8B?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4=E3=81=97=E3=81=9F=E3=81=93=E3=81=A8?= =?UTF-8?q?=E3=81=AB=E4=BC=B4=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/account.ts | 8 ++++---- packages/frontend/src/components/MkSignin.vue | 4 ++-- .../frontend/src/components/MkSigninDialog.vue | 5 +++-- .../frontend/src/components/MkSignupDialog.vue | 4 ++-- .../frontend/src/components/MkUserCardMini.vue | 2 +- .../frontend/src/pages/settings/accounts.vue | 18 +++++++++--------- packages/misskey-js/etc/misskey-js.api.md | 4 +++- packages/misskey-js/src/entities.ts | 2 +- 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/packages/frontend/src/account.ts b/packages/frontend/src/account.ts index 84d89b1b3f6a..b91834b94f3e 100644 --- a/packages/frontend/src/account.ts +++ b/packages/frontend/src/account.ts @@ -226,7 +226,7 @@ export async function openAccountMenu(opts: { function showSigninDialog() { const { dispose } = popup(defineAsyncComponent(() => import('@/components/MkSigninDialog.vue')), {}, { - done: res => { + done: (res: Misskey.entities.SigninFlowResponse & { finished: true }) => { addAccount(res.id, res.i); success(); }, @@ -236,9 +236,9 @@ export async function openAccountMenu(opts: { function createAccount() { const { dispose } = popup(defineAsyncComponent(() => import('@/components/MkSignupDialog.vue')), {}, { - done: res => { - addAccount(res.id, res.i); - switchAccountWithToken(res.i); + done: (res: Misskey.entities.SignupResponse) => { + addAccount(res.id, res.token); + switchAccountWithToken(res.token); }, closed: () => dispose(), }); diff --git a/packages/frontend/src/components/MkSignin.vue b/packages/frontend/src/components/MkSignin.vue index 26e1ac516c6c..077715a26ac0 100644 --- a/packages/frontend/src/components/MkSignin.vue +++ b/packages/frontend/src/components/MkSignin.vue @@ -83,7 +83,7 @@ import type { AuthenticationPublicKeyCredential } from '@github/webauthn-json/br import type { OpenOnRemoteOptions } from '@/scripts/please-login.js'; const emit = defineEmits<{ - (ev: 'login', v: Misskey.entities.SigninFlowResponse): void; + (ev: 'login', v: Misskey.entities.SigninFlowResponse & { finished: true }): void; }>(); const props = withDefaults(defineProps<{ @@ -276,7 +276,7 @@ async function tryLogin(req: Partial): Promi }); } -async function onLoginSucceeded(res: Misskey.entities.SigninFlowResponse & { finished: true; }) { +async function onLoginSucceeded(res: Misskey.entities.SigninFlowResponse & { finished: true }) { if (props.autoSet) { await login(res.i); } diff --git a/packages/frontend/src/components/MkSigninDialog.vue b/packages/frontend/src/components/MkSigninDialog.vue index 8351d7d5e044..8b1e9d9723a4 100644 --- a/packages/frontend/src/components/MkSigninDialog.vue +++ b/packages/frontend/src/components/MkSigninDialog.vue @@ -23,6 +23,7 @@ SPDX-License-Identifier: AGPL-3.0-only