From eda7a25320f6b0f694db6a2f4a0803336acd8897 Mon Sep 17 00:00:00 2001 From: Ali Mahdiyar Date: Wed, 23 Nov 2022 17:24:19 +0330 Subject: [PATCH 1/5] feat: add deeplink for opening BrightID on login form --- components/LoginForm.vue | 67 +++++++++++++++++++++++---------------- styles/pages/landing.scss | 13 ++++++++ 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/components/LoginForm.vue b/components/LoginForm.vue index d169e66..0940084 100644 --- a/components/LoginForm.vue +++ b/components/LoginForm.vue @@ -1,22 +1,22 @@ @@ -111,11 +114,11 @@ const LoginMethods = Object.freeze({ }) export default { components: {AppInput, AppButton}, - data() { return { + openBrightIdUrl: '', LoginMethods, - loginMethod: LoginMethods.explorerCode, + loginMethod: LoginMethods.localServer, hasErrors: true, explorer: { value: '', @@ -131,6 +134,12 @@ export default { }, } }, + mounted() { + this.openBrightIdUrl = 'brightid://local-server?run=true&next=' + window.location.href + if (this.$store.getters["app/isFirstVisitedRoute"]) { + this.loginByLocalServer('http://localhost:9025') + } + }, methods: { onInputValue(val) { @@ -162,8 +171,7 @@ export default { this.$store.commit('app/setLoading', false); } }, - async loginByLocalServer() { - const localServerUrl = `${this.localserver.value.startsWith('http://') ? '' : 'http://'}${this.localserver.value}` + async loginByLocalServer(localServerUrl) { const localServer = axios.create({ baseURL: localServerUrl, headers: { @@ -193,7 +201,10 @@ export default { if (this.loginMethod === LoginMethods.explorerCode) { this.loginByExplorerCode() } else if (this.loginMethod === LoginMethods.localServer) { - this.loginByLocalServer(); + if (this.localserver.value) { + const localServerUrl = `${this.localserver.value.startsWith('http://') ? '' : 'http://'}${this.localserver.value}` + this.loginByLocalServer(localServerUrl); + } } }, emmitError() { @@ -210,6 +221,6 @@ export default { visitLink(link) { window.open(link, '_blank') }, - }, + } } diff --git a/styles/pages/landing.scss b/styles/pages/landing.scss index 097c4d8..8de66ff 100644 --- a/styles/pages/landing.scss +++ b/styles/pages/landing.scss @@ -77,6 +77,19 @@ align-items: center; position: relative; margin-top: 22px; + + + &__open-brightid { + margin-bottom: 15px; + text-decoration: underline; + text-underline-offset: 3px; + } + + &__login-method { + display: flex; + width: 100%; + margin-bottom: 16px; + } } .form__btn-wrapper { From a1d9a2b8424a8fb475219b1c8c21ab6f8a66c8ba Mon Sep 17 00:00:00 2001 From: Ali Mahdiyar Date: Fri, 25 Nov 2022 00:54:09 +0330 Subject: [PATCH 2/5] refactor: local brightid server endpoint --- components/LoginForm.vue | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/LoginForm.vue b/components/LoginForm.vue index 0940084..6cb16e2 100644 --- a/components/LoginForm.vue +++ b/components/LoginForm.vue @@ -107,6 +107,7 @@ import axios from "axios" import AppInput from '~/components/AppInput.vue' import AppButton from '~/components/AppButton.vue' import {TOAST_ERROR} from '~/utils/constants' +import {encryptData} from "~/scripts/utils/crypto"; const LoginMethods = Object.freeze({ localServer: 'WiFi Sharing', @@ -178,15 +179,15 @@ export default { 'Access-Control-Allow-Origin': '*', }, }) - const explorerData = (await localServer.get('/v1/explorer-code')).data + const explorerData = (await localServer.get('/v1/info')).data if (explorerData) { const { - explorerCode, + id: brightId, password } = explorerData this.onInputValue({ id: 'explorer', - value: explorerCode, + value: encryptData(brightId, password), error: false, }) this.onInputValue({ From 4540d970260e701cdddcee574403c435f3a1ed0a Mon Sep 17 00:00:00 2001 From: Ali Mahdiyar Date: Fri, 25 Nov 2022 00:55:30 +0330 Subject: [PATCH 3/5] refactor: local brightid server endpoint --- components/LoginForm.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/LoginForm.vue b/components/LoginForm.vue index 6cb16e2..8a51622 100644 --- a/components/LoginForm.vue +++ b/components/LoginForm.vue @@ -179,7 +179,7 @@ export default { 'Access-Control-Allow-Origin': '*', }, }) - const explorerData = (await localServer.get('/v1/info')).data + const explorerData = (await localServer.get('/v1/user-info')).data if (explorerData) { const { id: brightId, From ab36371093c16036cae9da4678837b0b424b3d4c Mon Sep 17 00:00:00 2001 From: Ali Mahdiyar Date: Sun, 27 Nov 2022 21:44:00 +0330 Subject: [PATCH 4/5] refactor: login method test --- components/LoginForm.vue | 12 +++++------- cypress/e2e/auth.cy.ts | 11 ++++++----- utils/constants.ts | 5 +++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/components/LoginForm.vue b/components/LoginForm.vue index 8a51622..0f47ec1 100644 --- a/components/LoginForm.vue +++ b/components/LoginForm.vue @@ -7,6 +7,7 @@ :class="{ 'text-button form__btn-select__selected': loginMethod === l }" + :data-testid="`login-method-btn-${l.replace(' ', '')}`" class="text-button form__btn-select" @click.prevent="loginMethod = l" > @@ -83,7 +84,7 @@ /> @@ -106,13 +107,9 @@ import axios from "axios" import AppInput from '~/components/AppInput.vue' import AppButton from '~/components/AppButton.vue' -import {TOAST_ERROR} from '~/utils/constants' +import {LoginMethods, TOAST_ERROR} from '~/utils/constants' import {encryptData} from "~/scripts/utils/crypto"; -const LoginMethods = Object.freeze({ - localServer: 'WiFi Sharing', - explorerCode: 'Explorer Code', -}) export default { components: {AppInput, AppButton}, data() { @@ -138,7 +135,8 @@ export default { mounted() { this.openBrightIdUrl = 'brightid://local-server?run=true&next=' + window.location.href if (this.$store.getters["app/isFirstVisitedRoute"]) { - this.loginByLocalServer('http://localhost:9025') + this.loginByLocalServer('http://localhost:9025').catch(_err => { + }) } }, diff --git a/cypress/e2e/auth.cy.ts b/cypress/e2e/auth.cy.ts index 8ee9d38..6dcf9e7 100644 --- a/cypress/e2e/auth.cy.ts +++ b/cypress/e2e/auth.cy.ts @@ -6,11 +6,11 @@ import { FAKE_USER_EXPLORER_CODE, LOCAL_FORAGE_DATA, } from '../utils/data' -import { TOAST_ERROR } from '../../utils/constants' +import {LoginMethods, TOAST_ERROR} from '../../utils/constants' describe('Auth', () => { beforeEach(() => { - localforage.config({ storeName: 'nuxtLocalForage', name: 'nuxtJS' }) + localforage.config({storeName: 'nuxtLocalForage', name: 'nuxtJS'}) localforage.removeItem('profileData') cy.profileIntercepts() }) @@ -24,6 +24,7 @@ describe('Auth', () => { window.localStorage.removeItem('privateKey') }, }) + cy.get(`[data-testid=login-method-btn-${LoginMethods.explorerCode.replace(' ', '')}]`).click() cy.get('[data-testid=login-explorer-code]').type(FAKE_USER_EXPLORER_CODE) cy.get('[data-testid=login-password]').type(FAKE_BRIGHT_ID_PASSWORD) cy.get('[data-testid=login-submit]').click() @@ -42,7 +43,7 @@ describe('Auth', () => { doLogin() } - it('login', () => { + it('login by explorer code', () => { doLoginSuccess() cy.wait('@explorerCode') .its('request.body') @@ -61,7 +62,7 @@ describe('Auth', () => { cy.url() .should('include', `/profile/${FAKE_BRIGHT_ID}`) .then(async () => { - localforage.config({ storeName: 'nuxtLocalForage', name: 'nuxtJS' }) + localforage.config({storeName: 'nuxtLocalForage', name: 'nuxtJS'}) const data = await localforage.getItem('profileData') expect(data).to.deep.eq(LOCAL_FORAGE_DATA) }) @@ -76,7 +77,7 @@ describe('Auth', () => { expect(localStorage.getItem('authKey')).to.be.null expect(localStorage.getItem('publicKey')).to.be.null expect(localStorage.getItem('privateKey')).to.be.null - localforage.config({ storeName: 'nuxtLocalForage', name: 'nuxtJS' }) + localforage.config({storeName: 'nuxtLocalForage', name: 'nuxtJS'}) const data = await localforage.getItem('profileData') expect(data).to.be.null } diff --git a/utils/constants.ts b/utils/constants.ts index bffce98..e33acaa 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -23,3 +23,8 @@ export const RATING_INBOUND_STAT = 'ri' export const RATING_OUTBOUND_STAT = 'ro' export const ENERGY_INBOUND_STAT = 'ei' export const ENERGY_OUTBOUND_STAT = 'eo' + +export const LoginMethods = Object.freeze({ + localServer: 'WiFi Sharing', + explorerCode: 'Explorer Code', +}) From 4b6468ebd494cfa0d157df4bc9c82dde76b4883b Mon Sep 17 00:00:00 2001 From: Ali Mahdiyar Date: Fri, 23 Dec 2022 21:17:01 +0330 Subject: [PATCH 5/5] fix: use local ip instead of localhost for safari security restriction --- components/LoginForm.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/LoginForm.vue b/components/LoginForm.vue index 0f47ec1..f11f98c 100644 --- a/components/LoginForm.vue +++ b/components/LoginForm.vue @@ -135,7 +135,7 @@ export default { mounted() { this.openBrightIdUrl = 'brightid://local-server?run=true&next=' + window.location.href if (this.$store.getters["app/isFirstVisitedRoute"]) { - this.loginByLocalServer('http://localhost:9025').catch(_err => { + this.loginByLocalServer('http://127.0.0.1:9025').catch(_err => { }) } },