From 2de92be07461a57dab775bf384b1e9ddb001934e Mon Sep 17 00:00:00 2001 From: Anthony Potdevin Date: Wed, 5 Aug 2020 23:44:05 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=94=A7=20sso=20and=20login=20hel?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/schema/auth/resolvers.ts | 16 +++-- server/schema/types.ts | 2 +- src/components/accounts/ServerAccounts.tsx | 7 ++- src/graphql/types.ts | 2 +- src/views/homepage/Accounts.tsx | 71 ++++++++++++++++------ 5 files changed, 72 insertions(+), 26 deletions(-) diff --git a/server/schema/auth/resolvers.ts b/server/schema/auth/resolvers.ts index 6082e640..9727a7f5 100644 --- a/server/schema/auth/resolvers.ts +++ b/server/schema/auth/resolvers.ts @@ -17,27 +17,31 @@ const { cookiePath, nodeEnv } = serverRuntimeConfig || {}; export const authResolvers = { Query: { - getAuthToken: async (_: undefined, params: any, context: ContextType) => { + getAuthToken: async ( + _: undefined, + params: any, + context: ContextType + ): Promise => { const { ip, secret, sso, res } = context; await requestLimiter(ip, 'getAuthToken'); if (!sso) { logger.warn('No SSO account available'); - return null; + return false; } if (!sso.socket || !sso.macaroon) { logger.warn('Host and macaroon are required for SSO'); - return null; + return false; } if (!params.cookie) { - return null; + return false; } if (cookiePath === '') { logger.warn('SSO auth not available since no cookie path was provided'); - return null; + return false; } const cookieFile = readCookie(cookiePath); @@ -61,7 +65,7 @@ export const authResolvers = { } logger.debug(`Cookie ${params.cookie} different to file ${cookieFile}`); - return null; + return false; }, getSessionToken: async ( _: undefined, diff --git a/server/schema/types.ts b/server/schema/types.ts index 5df889cd..d4416f51 100644 --- a/server/schema/types.ts +++ b/server/schema/types.ts @@ -79,7 +79,7 @@ export const queryTypes = gql` initialize: Boolean lastMessage: String ): getMessagesType - getAuthToken(cookie: String): Boolean + getAuthToken(cookie: String): Boolean! getSessionToken(id: String, password: String): Boolean getServerAccounts: [serverAccountType] getAccount: serverAccountType diff --git a/src/components/accounts/ServerAccounts.tsx b/src/components/accounts/ServerAccounts.tsx index f97dcc5e..2ce8297a 100644 --- a/src/components/accounts/ServerAccounts.tsx +++ b/src/components/accounts/ServerAccounts.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { useRouter } from 'next/router'; import { getUrlParam } from 'src/utils/url'; import { useGetAuthTokenQuery } from 'src/graphql/queries/__generated__/getAuthToken.generated'; +import { toast } from 'react-toastify'; export const ServerAccounts: React.FC = () => { const { push, query } = useRouter(); @@ -15,9 +16,13 @@ export const ServerAccounts: React.FC = () => { }); React.useEffect(() => { - if (cookieParam && authData && authData.getAuthToken) { + if (!cookieParam || !authData) return; + if (authData.getAuthToken) { push('/'); } + if (!authData.getAuthToken) { + toast.warning('Unable to SSO. Check your logs.'); + } }, [push, authData, cookieParam]); return null; diff --git a/src/graphql/types.ts b/src/graphql/types.ts index 00ed20f1..6b42ef62 100644 --- a/src/graphql/types.ts +++ b/src/graphql/types.ts @@ -75,7 +75,7 @@ export type Query = { getChainTransactions?: Maybe>>; getUtxos?: Maybe>>; getMessages?: Maybe; - getAuthToken?: Maybe; + getAuthToken: Scalars['Boolean']; getSessionToken?: Maybe; getServerAccounts?: Maybe>>; getAccount?: Maybe; diff --git a/src/views/homepage/Accounts.tsx b/src/views/homepage/Accounts.tsx index 25c16daa..b7a2fc98 100644 --- a/src/views/homepage/Accounts.tsx +++ b/src/views/homepage/Accounts.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import styled from 'styled-components'; import { toast } from 'react-toastify'; -import { Lock, Unlock } from 'react-feather'; +import { Lock, Unlock, ChevronDown, ChevronUp } from 'react-feather'; import { chartColors } from 'src/styles/Themes'; import { useRouter } from 'next/router'; import { useGetCanConnectLazyQuery } from 'src/graphql/queries/__generated__/getNodeInfo.generated'; @@ -10,7 +10,13 @@ import { useGetServerAccountsQuery } from 'src/graphql/queries/__generated__/get import { ServerAccountType } from 'src/graphql/types'; import { LoadingCard } from 'src/components/loading/LoadingCard'; import { Section } from '../../components/section/Section'; -import { Card, SingleLine } from '../../components/generic/Styled'; +import { + Card, + SingleLine, + DarkSubTitle, + Sub4Title, + Separation, +} from '../../components/generic/Styled'; import { ColorButton } from '../../components/buttons/colorButton/ColorButton'; import { ConnectTitle, LockPadding } from './HomePage.styled'; import { Login } from './Login'; @@ -19,20 +25,51 @@ const AccountLine = styled.div` margin: 8px 0; `; -const renderIntro = () => ( -
- Hi! Welcome to ThunderHub - - {'To start you must create an account on your server. '} - - You can find instructions for this here. - - -
-); +const DetailsLine = styled.div` + display: flex; + align-items: center; + width: 100%; + justify-content: space-between; + cursor: pointer; +`; + +const RenderIntro = () => { + const [detailsOpen, setDetailsOpen] = React.useState(false); + return ( +
+ Hi! Welcome to ThunderHub + + {'To start you must create an account on your server. '} + + You can find instructions for this here. + + + + setDetailsOpen(p => !p)}> + {'Did you already create accounts?'} + {detailsOpen ? : } + + {detailsOpen && ( + <> + + + The accounts might be missing information that is needed for them + to be available. Please check your logs to see if there is + anything missing. + + + On server start you will see a log message of the accounts that + will be available. + + + )} + +
+ ); +}; export const Accounts = () => { const { push } = useRouter(); @@ -67,7 +104,7 @@ export const Accounts = () => { } if (!accountData?.getServerAccounts?.length) { - return renderIntro(); + return ; } const getTitle = (account: ServerAccountType) => {