Skip to content

Commit

Permalink
Improve login operations
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek555 committed Mar 28, 2024
1 parent 978383f commit 606cdc6
Show file tree
Hide file tree
Showing 40 changed files with 1,369 additions and 772 deletions.
22 changes: 11 additions & 11 deletions apps/auth/__tests__/validate-hive-password.spec.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { expect, test } from '@jest/globals';
import { validateHivePassword } from '../../../packages/smart-signer/lib/validators/validate-hive-password';
import { validateWifKey } from '../../../packages/smart-signer/lib/validators/validate-wif-key';

const t = (v) => v;
const runValidateHivePassword = (v) => {
return validateHivePassword(v, t);
const runValidateWifKey = (v) => {
return validateWifKey(v, t);
}

test('test validator function runValidateHivePassword', () => {
test('test validator function runValidateWifKey', () => {

expect(runValidateHivePassword('5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw')).toBeNull();
expect(runValidateHivePassword('P5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw')).toBeNull();
expect(runValidateWifKey('5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw')).toBeNull();
expect(runValidateWifKey('P5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw')).toBeNull();

expect(runValidateHivePassword(''))
expect(runValidateWifKey(''))
.toBe('chainvalidation_js.password_should_not_be_empty');
expect(runValidateHivePassword('aa'))
expect(runValidateWifKey('aa'))
.toBe('chainvalidation_js.invalid_password_format');
expect(runValidateHivePassword('5A'))
expect(runValidateWifKey('5A'))
.toBe('chainvalidation_js.invalid_password_format');
expect(runValidateHivePassword('P5A'))
expect(runValidateWifKey('P5A'))
.toBe('chainvalidation_js.invalid_password_format');

expect(runValidateHivePassword('5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsa'))
expect(runValidateWifKey('5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsa'))
.toBe('chainvalidation_js.invalid_password_checksum');

});
8 changes: 8 additions & 0 deletions apps/auth/components/site-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ const SiteHeader: FC = () => {
</Link>
)}

{isClient && user?.isLoggedIn === false && (
<Link href="/signin">
<Button variant="redHover" size="sm" className="h-10">
Sign In
</Button>
</Link>
)}

{isClient && user?.isLoggedIn === true && (
<Link
href=""
Expand Down
9 changes: 5 additions & 4 deletions apps/auth/pages/login.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { GetServerSideProps } from 'next';
import { getTranslations } from '@/auth/lib/get-translations';
import { loginPageController } from '@smart-signer/lib/login-page-controller';

// import { LoginPanel } from '@smart-signer/components/login-panel';
import { LoginPanel } from '@smart-signer/components/signin-panel';
import { LoginPanel } from '@smart-signer/components/login-panel';

export default function LoginPage() {

return (
<div className="mx-2 flex flex-col pt-10">
<LoginPanel />
<LoginPanel
authenticateOnBackend={true}
strict={true}
/>
</div>
);
}
Expand Down
31 changes: 31 additions & 0 deletions apps/auth/pages/signin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { GetServerSideProps } from 'next';
import { getTranslations } from '@/auth/lib/get-translations';
import { loginPageController } from '@smart-signer/lib/login-page-controller';
import { LoginPanel } from '@smart-signer/components/signin-panel';
import { LoginType } from '@smart-signer/types/common';

export default function LoginPage() {

return (
<div className="mx-2 flex flex-col pt-10">
<LoginPanel
authenticateOnBackend={false}
strict={false}
enabledLoginTypes={[
LoginType.hbauth,
LoginType.keychain,
LoginType.wif,
]}
/>
</div>
);
}

export const getServerSideProps: GetServerSideProps = async (ctx) => {
return {
props: {
...(await loginPageController(ctx)),
...(await getTranslations(ctx))
}
};
};
1 change: 0 additions & 1 deletion apps/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"react-dom": "18.2.0",
"react-hook-form": "^7.49.2",
"react-intersection-observer": "^9.5.2",
"react-spinners-kit": "^1.9.1",
"recharts": "^2.10.4",
"remarkable": "^2.0.1",
"sanitize-html": "^2.11.0",
Expand Down
5 changes: 4 additions & 1 deletion apps/wallet/components/dialog-login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ function DialogLogin({ children }: { children: ReactNode }) {
<Dialog>
<DialogTrigger asChild>{children}</DialogTrigger>
<DialogContent className="sm:max-w-[600px]" data-testid="login-dialog">
<LoginPanel />
<LoginPanel
authenticateOnBackend={false}
strict={false}
/>
</DialogContent>
</Dialog>
);
Expand Down
1 change: 0 additions & 1 deletion apps/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"next-transpile-modules": "^10.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-spinners-kit": "^1.9.1",
"recharts": "^2.10.3",
"zod": "^3.22.4"
},
Expand Down
64 changes: 42 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions packages/smart-signer/components/auth/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export enum Steps {
OTHER_LOGIN_DETAILS
}

const SignInForm = forwardRef<SignInFormRef, SignInFormProps>(({ preferredKeyTypes, onComplete, i18nNamespace = 'smart-signer' }, ref) => {
const SignInForm = forwardRef<SignInFormRef, SignInFormProps>((
{ preferredKeyTypes, onComplete, i18nNamespace = 'smart-signer' },
ref
) => {
// component controllers
const [step, setStep] = useState<Steps>(Steps.SAFE_STORAGE_LOGIN);
const { t } = useTranslation(i18nNamespace);
Expand All @@ -42,9 +45,10 @@ const SignInForm = forwardRef<SignInFormRef, SignInFormProps>(({ preferredKeyTyp
}
}));

// final form handlers
// Final form handlers.
// TODO Some arguments for useProcessAuth should be read from env variables.
// TODO: replace with function
const { submitAuth, signAuth, isSigned } = useProcessAuth(t);
const { submitAuth, signAuth, isSigned } = useProcessAuth(t, false, false);

async function sign(loginType: LoginType, username: string, keyType: KeyType): Promise<void> {
const schema: LoginFormSchema = {
Expand Down Expand Up @@ -81,7 +85,7 @@ const SignInForm = forwardRef<SignInFormRef, SignInFormProps>(({ preferredKeyTyp
}

{
// TODO: Extract this to separate component
// TODO: Extract this to separate component
(step === Steps.OTHER_LOGIN_OPTIONS &&
<Methods onSetStep={setStep} i18nNamespace={i18nNamespace} />
)
Expand Down
Loading

0 comments on commit 606cdc6

Please sign in to comment.