From cc0639e308611a3213321780c0d9cdd8b63f0434 Mon Sep 17 00:00:00 2001 From: kharann Date: Wed, 18 Mar 2020 17:09:11 +0100 Subject: [PATCH 01/12] Added inputs for password and email --- src/common/base.scss | 4 +++- src/components/LoginField.vue | 25 +++++++++++++++++++++++++ src/components/shared/TextInput.vue | 8 +++++++- src/views/Login.vue | 5 ++++- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/components/LoginField.vue diff --git a/src/common/base.scss b/src/common/base.scss index a022d63..cfdc285 100644 --- a/src/common/base.scss +++ b/src/common/base.scss @@ -48,6 +48,7 @@ label { input[type="text"], input[type="tel"], +input[type="password"], textarea { width: 100%; color: $color-text; @@ -58,7 +59,8 @@ textarea { } input[type="text"], -input[type="tel"] { +input[type="tel"], +input[type="password"] { max-width: 200px; } diff --git a/src/components/LoginField.vue b/src/components/LoginField.vue new file mode 100644 index 0000000..7f08c0c --- /dev/null +++ b/src/components/LoginField.vue @@ -0,0 +1,25 @@ + + + + + diff --git a/src/components/shared/TextInput.vue b/src/components/shared/TextInput.vue index 7a8ac6f..0ded129 100644 --- a/src/components/shared/TextInput.vue +++ b/src/components/shared/TextInput.vue @@ -2,7 +2,7 @@
Se her for mer informasjon.

+ From 03c61aa0bb0511c89c9706c8b6bc9f20309e5e28 Mon Sep 17 00:00:00 2001 From: kharann Date: Wed, 18 Mar 2020 20:48:58 +0100 Subject: [PATCH 02/12] Renamed GoogleLoginButton and added LoginFIeld --- ...{LoginButton.vue => GoogleLoginButton.vue} | 2 +- src/components/LoginField.vue | 88 ++++++++++++++++++- src/helpers/authentication.js | 37 ++++++++ src/views/Login.vue | 40 ++++++++- 4 files changed, 159 insertions(+), 8 deletions(-) rename src/components/{LoginButton.vue => GoogleLoginButton.vue} (98%) create mode 100644 src/helpers/authentication.js diff --git a/src/components/LoginButton.vue b/src/components/GoogleLoginButton.vue similarity index 98% rename from src/components/LoginButton.vue rename to src/components/GoogleLoginButton.vue index d868487..e1bc583 100644 --- a/src/components/LoginButton.vue +++ b/src/components/GoogleLoginButton.vue @@ -12,7 +12,7 @@ import firebase from "firebase"; import fb from "@/firebaseConfig.js"; export default { - name: "LoginButton", + name: "GoogleLoginButton", methods: { socialLogin() { const provider = new firebase.auth.GoogleAuthProvider(); diff --git a/src/components/LoginField.vue b/src/components/LoginField.vue index 7f08c0c..d3273d2 100644 --- a/src/components/LoginField.vue +++ b/src/components/LoginField.vue @@ -1,25 +1,105 @@ diff --git a/src/helpers/authentication.js b/src/helpers/authentication.js new file mode 100644 index 0000000..e83eb04 --- /dev/null +++ b/src/helpers/authentication.js @@ -0,0 +1,37 @@ +import firebase from "firebase"; +import fb from "@/firebaseConfig.js"; + +const loginUser = context => { + const { currentUser } = firebase.auth(); + fb.additionalUserInfoCollection + .doc(currentUser.uid) + .get() + .then(userInfo => { + if (userInfo.data() && userInfo.data().phoneNumber) { + context.$store.dispatch("SET_CURRENT_USER", { + ...currentUser, + ...userInfo.data() + }); + context.$router.replace("home"); + } else { + context.$dialog + .prompt({ + title: "Telefonnummer", + body: "Skriv inn telefonnummeret ditt uten landskode", + promptHelp: "" + }) + .then(dialog => { + fb.additionalUserInfoCollection + .doc(currentUser.uid) + .set({ phoneNumber: dialog.data }); + context.$store.dispatch("SET_CURRENT_USER", { + ...currentUser, + phoneNumber: dialog.data + }); + context.$router.replace("home"); + }); + } + }); +}; + +export default loginUser; diff --git a/src/views/Login.vue b/src/views/Login.vue index fa96a40..c683c02 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -23,19 +23,20 @@ >Se her for mer informasjon.

+ +
- + + diff --git a/src/components/LoginField.vue b/src/components/LoginField.vue deleted file mode 100644 index d3273d2..0000000 --- a/src/components/LoginField.vue +++ /dev/null @@ -1,105 +0,0 @@ - - - - - diff --git a/src/components/shared/Button.vue b/src/components/shared/Button.vue index c099edd..19b739e 100644 --- a/src/components/shared/Button.vue +++ b/src/components/shared/Button.vue @@ -1,6 +1,6 @@ From 98a88a91a26b09d042126e5d2d39ea9174513f3d Mon Sep 17 00:00:00 2001 From: kharann Date: Wed, 18 Mar 2020 22:20:40 +0100 Subject: [PATCH 04/12] Import correctly in googleloginbutton --- src/components/GoogleLoginButton.vue | 2 +- src/helpers/authentication.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/GoogleLoginButton.vue b/src/components/GoogleLoginButton.vue index 12bbade..49145ba 100644 --- a/src/components/GoogleLoginButton.vue +++ b/src/components/GoogleLoginButton.vue @@ -9,7 +9,7 @@ @@ -132,4 +143,9 @@ export default { text-align: center; color: $color-danger; } + +.success { + text-align: center; + color: #066f06; +} diff --git a/src/helpers/authentication.js b/src/helpers/authentication.js index 26e8c31..16f8d05 100644 --- a/src/helpers/authentication.js +++ b/src/helpers/authentication.js @@ -52,16 +52,10 @@ export const getErrorMessage = errorCode => { return "Passordet er feil!"; case "auth/invalid-email": return "Formatet på mailen er feil!"; - case "auth/wrong-password": - return "Passordet er feil"; - case "auth/weak-password": - return "Passordet må inneholde minst 6 tegn"; case "auth/email-already-in-use": return "Mailen skrevet inn er allerede i bruk"; case "auth/too-many-requests": return "For mange login forsøk, prøv igjen senere"; - case "auth/user-not-found": - return "Vi finner ingen bruker lenket til denne mailen"; default: return `Ukjent errorkode: ${errorCode}`; } From e9bde693184dbd7deeee4b108300ccff7d5a59d1 Mon Sep 17 00:00:00 2001 From: kharann Date: Thu, 19 Mar 2020 13:34:51 +0100 Subject: [PATCH 08/12] Different redirect url in prod --- src/components/LoginArea.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/LoginArea.vue b/src/components/LoginArea.vue index e95d759..3b2aa50 100644 --- a/src/components/LoginArea.vue +++ b/src/components/LoginArea.vue @@ -51,7 +51,10 @@ export default { const actionCodeSettings = { // URL you want to redirect back to. The domain (www.example.com) for this // URL must be whitelisted in the Firebase Console. - url: "http://localhost:8080/login", + url: + process.env.NODE_ENV === "PRODUCTION" + ? "https://karantenehjelpen.no/login" + : "http://localhost:8080/login", // This must be true. handleCodeInApp: true, lang: "no" From 03f34b0c72756dfe7dd54890a456388f9b136167 Mon Sep 17 00:00:00 2001 From: kharann Date: Thu, 19 Mar 2020 14:08:13 +0100 Subject: [PATCH 09/12] Dynamic redirect url depending on developement/production --- src/components/LoginArea.vue | 15 +++++++++------ src/helpers/authentication.js | 13 +++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/components/LoginArea.vue b/src/components/LoginArea.vue index 3b2aa50..0804729 100644 --- a/src/components/LoginArea.vue +++ b/src/components/LoginArea.vue @@ -26,7 +26,11 @@ - - diff --git a/src/helpers/auth.js b/src/helpers/auth.js index 1bf7171..77ac1be 100644 --- a/src/helpers/auth.js +++ b/src/helpers/auth.js @@ -1,7 +1,7 @@ import firebase from "firebase"; import fb from "@/firebaseConfig.js"; -export default (context, user) => { +export const handleSignedIn = (context, user) => { fb.additionalUserInfoCollection .doc(user.uid) .get() @@ -43,3 +43,31 @@ export default (context, user) => { } }); }; + +export const getErrorMessage = errorCode => { + switch (errorCode) { + case "auth/invalid-password": + return "Passordet er feil!"; + case "auth/invalid-email": + return "Formatet på mailen er feil!"; + case "auth/email-already-in-use": + return "Mailen skrevet inn er allerede i bruk"; + case "auth/too-many-requests": + return "For mange login forsøk, prøv igjen senere"; + default: + return `Ukjent errorkode: ${errorCode}`; + } +}; + +export const getRedirectUrl = (buildState, projectid) => { + let url; + if (buildState === "production") { + url = + projectid === "karantenehjelpen-test" + ? "https://karantenehjelpen-test.firebaseapp.com/login" + : "https://www.karantenehjelpen.no/login"; + } else { + url = "http://localhost:8080/login"; + } + return url; +}; diff --git a/src/views/Login.vue b/src/views/Login.vue index 0293be4..abad525 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -33,10 +33,7 @@ import GoogleLoginButton from "@/components/GoogleLoginButton.vue"; import LoginArea from "@/components/LoginArea.vue"; import firebase from "firebase"; - -import handleSignedIn from "@/helpers/auth"; - -import LoginButton from "@/components/LoginButton.vue"; +import { handleSignedIn } from "@/helpers/auth"; export default { name: "login", From bb89c8b7d888c47c13417755f9cc215c4acf3650 Mon Sep 17 00:00:00 2001 From: kharann Date: Thu, 19 Mar 2020 16:47:49 +0100 Subject: [PATCH 11/12] delete duplicate helper --- src/helpers/authentication.js | 75 ----------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 src/helpers/authentication.js diff --git a/src/helpers/authentication.js b/src/helpers/authentication.js deleted file mode 100644 index 96751a7..0000000 --- a/src/helpers/authentication.js +++ /dev/null @@ -1,75 +0,0 @@ -import firebase from "firebase"; -import fb from "@/firebaseConfig.js"; - -export const authenticateUser = context => { - console.log(context); - const { currentUser } = firebase.auth(); - fb.additionalUserInfoCollection - .doc(currentUser.uid) - .get() - .then(userInfo => { - if (userInfo.data() && userInfo.data().phoneNumber) { - context.$store.dispatch("SET_CURRENT_USER", { - ...currentUser, - ...userInfo.data() - }); - context.$router.replace("home"); - } else { - context.$dialog - .prompt({ - title: "Telefonnummer", - body: "Skriv inn telefonnummeret ditt uten landskode", - promptHelp: "" - }) - .then(dialog => { - fb.additionalUserInfoCollection - .doc(currentUser.uid) - .set({ phoneNumber: dialog.data }); - context.$store.dispatch("SET_CURRENT_USER", { - ...currentUser, - phoneNumber: dialog.data - }); - context.$router.replace("home"); - }) - .catch(() => { - firebase - .auth() - .signOut() - .then(() => { - context.$store.dispatch("SET_CURRENT_USER", null); - }) - .catch(error => { - console.log(`something went wrong ${error.message}`); - }); - }); - } - }); -}; - -export const getErrorMessage = errorCode => { - switch (errorCode) { - case "auth/invalid-password": - return "Passordet er feil!"; - case "auth/invalid-email": - return "Formatet på mailen er feil!"; - case "auth/email-already-in-use": - return "Mailen skrevet inn er allerede i bruk"; - case "auth/too-many-requests": - return "For mange login forsøk, prøv igjen senere"; - default: - return `Ukjent errorkode: ${errorCode}`; - } -}; - -export const getRedirectUrl = (buildState, projectid) => { - let url; - if (buildState === "production") { - url = - projectid === "karantenehjelpen-test" - ? "https://karantenehjelpen-test.firebaseapp.com/login" - : "https://www.karantenehjelpen.no/login"; - } else { - url = "http://localhost:8080/login"; - } - return url; -}; From e134a6946bf37110ab35595ef5daf69a2436a61d Mon Sep 17 00:00:00 2001 From: kharann Date: Thu, 19 Mar 2020 18:17:35 +0100 Subject: [PATCH 12/12] use window.location.origin when getting redirect url --- src/components/LoginArea.vue | 5 +---- src/helpers/auth.js | 13 ++----------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/components/LoginArea.vue b/src/components/LoginArea.vue index 4a7d11b..9c89276 100644 --- a/src/components/LoginArea.vue +++ b/src/components/LoginArea.vue @@ -55,10 +55,7 @@ export default { const actionCodeSettings = { // URL you want to redirect back to. The domain (www.example.com) for this // URL must be whitelisted in the Firebase Console. - url: getRedirectUrl( - process.env.NODE_ENV, - firebase.app().options.projectId - ), + url: getRedirectUrl(), // This must be true. handleCodeInApp: true, lang: "no" diff --git a/src/helpers/auth.js b/src/helpers/auth.js index 77ac1be..ce8e83f 100644 --- a/src/helpers/auth.js +++ b/src/helpers/auth.js @@ -59,15 +59,6 @@ export const getErrorMessage = errorCode => { } }; -export const getRedirectUrl = (buildState, projectid) => { - let url; - if (buildState === "production") { - url = - projectid === "karantenehjelpen-test" - ? "https://karantenehjelpen-test.firebaseapp.com/login" - : "https://www.karantenehjelpen.no/login"; - } else { - url = "http://localhost:8080/login"; - } - return url; +export const getRedirectUrl = () => { + return `${window.location.origin}/login`; };