From 3e6af89a9b0250c76208b3dfd904c56e59b78872 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 4 Oct 2023 18:07:49 -0500 Subject: [PATCH] Enable Nostr registration --- src/actions/accounts.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/actions/accounts.ts b/src/actions/accounts.ts index 27cf94455..779966596 100644 --- a/src/actions/accounts.ts +++ b/src/actions/accounts.ts @@ -1,5 +1,8 @@ +import { nip19 } from 'nostr-tools'; + import { importEntities } from 'soapbox/entity-store/actions'; import { Entities } from 'soapbox/entity-store/entities'; +import { getPublicKey } from 'soapbox/features/nostr/sign'; import { selectAccount } from 'soapbox/selectors'; import { isLoggedIn } from 'soapbox/utils/auth'; import { getFeatures, parseVersion, PLEROMA } from 'soapbox/utils/features'; @@ -128,9 +131,15 @@ const maybeRedirectLogin = (error: AxiosError, history?: History) => { const noOp = () => new Promise(f => f(undefined)); const createAccount = (params: Record) => - (dispatch: AppDispatch, getState: () => RootState) => { + async (dispatch: AppDispatch, getState: () => RootState) => { + const { instance } = getState(); + const { nostrSignup } = getFeatures(instance); + const pubkey = nostrSignup ? await getPublicKey() : undefined; + dispatch({ type: ACCOUNT_CREATE_REQUEST, params }); - return api(getState, 'app').post('/api/v1/accounts', params).then(({ data: token }) => { + return api(getState, 'app').post('/api/v1/accounts', params, { + headers: pubkey ? { authorization: `Bearer ${nip19.npubEncode(pubkey)}` } : undefined, + }).then(({ data: token }) => { return dispatch({ type: ACCOUNT_CREATE_SUCCESS, params, token }); }).catch(error => { dispatch({ type: ACCOUNT_CREATE_FAIL, error, params });