chore: fix auth encoding

This commit is contained in:
AP 2020-02-04 08:04:50 +01:00
parent 388f0343ee
commit bf5b7d4250
2 changed files with 13 additions and 12 deletions

View file

@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react';
import { useAccount } from '../../context/AccountContext';
import { saveUserAuth, getAuthString, saveSessionAuth } from '../../utils/auth';
import CryptoJS from 'crypto-js';
import base64url from 'base64url';
import { PasswordInput } from './Password';
import { useLazyQuery } from '@apollo/react-hooks';
import { GET_CAN_CONNECT } from '../../graphql/query';
@ -63,9 +62,9 @@ export const LoginForm = ({
useEffect(() => {
if (!loading && data && data.getNodeInfo && data.getNodeInfo.alias) {
const admin = base64url.fromBase64(isAdmin);
const read = base64url.fromBase64(isRead);
const cert = base64url.fromBase64(isCert);
const admin = isAdmin;
const read = isRead;
const cert = isCert;
const encryptedAdmin =
admin && isPass !== ''
@ -114,9 +113,9 @@ export const LoginForm = ({
]);
const handleConnect = () => {
const admin = base64url.fromBase64(isAdmin);
const read = base64url.fromBase64(isRead);
const cert = base64url.fromBase64(isCert);
const admin = isAdmin;
const read = isRead;
const cert = isCert;
const correctMacaroon = read ? read : admin;

View file

@ -74,13 +74,15 @@ export const getAuthLnd = (lndconnect: string) => {
const macaroon = url.searchParams.get('macaroon') || '';
const socket = url.host;
return { cert, macaroon, socket };
return {
cert: base64url.toBase64(cert),
macaroon: base64url.toBase64(macaroon),
socket,
};
};
export const getBase64CertfromDerFormat = (url: string) => {
if (!url) return null;
const base64 = base64url.toBase64(url);
export const getBase64CertfromDerFormat = (base64: string) => {
if (!base64) return null;
const prefix = '-----BEGIN CERTIFICATE-----\n';
const postfix = '-----END CERTIFICATE-----';