kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Enable Nostr registration
rodzic
28731f6087
commit
3e6af89a9b
|
@ -1,5 +1,8 @@
|
||||||
|
import { nip19 } from 'nostr-tools';
|
||||||
|
|
||||||
import { importEntities } from 'soapbox/entity-store/actions';
|
import { importEntities } from 'soapbox/entity-store/actions';
|
||||||
import { Entities } from 'soapbox/entity-store/entities';
|
import { Entities } from 'soapbox/entity-store/entities';
|
||||||
|
import { getPublicKey } from 'soapbox/features/nostr/sign';
|
||||||
import { selectAccount } from 'soapbox/selectors';
|
import { selectAccount } from 'soapbox/selectors';
|
||||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||||
import { getFeatures, parseVersion, PLEROMA } from 'soapbox/utils/features';
|
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 noOp = () => new Promise(f => f(undefined));
|
||||||
|
|
||||||
const createAccount = (params: Record<string, any>) =>
|
const createAccount = (params: Record<string, any>) =>
|
||||||
(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 });
|
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 });
|
return dispatch({ type: ACCOUNT_CREATE_SUCCESS, params, token });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ACCOUNT_CREATE_FAIL, error, params });
|
dispatch({ type: ACCOUNT_CREATE_FAIL, error, params });
|
||||||
|
|
Ładowanie…
Reference in New Issue