Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #175 from s0lvang/feature/better_feedback_on_email…
Browse files Browse the repository at this point in the history
…link

Endra epost sent meldingen og error tilbakemeldingen når mailen ikke er funnet i localStorage
  • Loading branch information
kharann authored Mar 20, 2020
2 parents 5ea8064 + c2fc1df commit 1cb7ac1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/components/LoginArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
</div>
<p class="error" v-if="errorCode">{{ errorMessage }}</p>
<p class="success" v-if="sentMail">
Sjekk eposten din for lenke å logge inn med!
En lenke du kan logge inn med har blitt sendt til {{ email }} <br />
Mailen kan ta et par minuter. Husk også å sjekk spam/søppeldunken!
</p>
</div>
</template>

<script>
import { getErrorMessage, handleSignedIn } from "@/helpers/auth";
import { registerWithEmail, login } from "@/services/firebase";
import { registerWithEmail, login, isAuthLink } from "@/services/firebase";
import Button from "@/components/shared/Button.vue";
export default {
Expand All @@ -43,7 +44,7 @@ export default {
},
computed: {
errorMessage() {
return getErrorMessage(this.errorCode);
return getErrorMessage(this.errorCode, isAuthLink(window.location.href));
}
},
methods: {
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ export const setUpGoogleSignInCompleteListener = async (
callback(await firebase.auth().getRedirectResult());
};

export const getErrorMessage = errorCode => {
export const getErrorMessage = (errorCode, isAuthLink) => {
switch (errorCode) {
case "auth/invalid-password":
return "Passordet er feil!";
case "auth/invalid-email":
return "Formatet på mailen er feil!";
return isAuthLink
? "Epostadressen skrevet inn er ikke den samme som denne lenken ble sendt til, last siden på nytt og prøv igjen!"
: "Epostadressen skrevet inn er ugyldig";
case "auth/email-already-in-use":
return "Mailen skrevet inn er allerede i bruk";
case "auth/too-many-requests":
Expand Down
23 changes: 13 additions & 10 deletions src/services/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const retrieveRequest = (userId, requestId) =>
* HELPERS END
*/

export const signOut = async (callback = () => { }) => {
export const signOut = async (callback = () => {}) => {
await fb.auth().signOut();

callback();
Expand All @@ -35,7 +35,7 @@ const ACTION_CODE_SETTINGS = {
* @returns string if error, null if success
* @param {Function} callback Callback on success
*/
export const registerWithEmail = async (email, callback = () => { }) => {
export const registerWithEmail = async (email, callback = () => {}) => {
try {
await fb.auth().sendSignInLinkToEmail(email, ACTION_CODE_SETTINGS);
window.localStorage.setItem("emailForSignIn", email);
Expand All @@ -44,14 +44,17 @@ export const registerWithEmail = async (email, callback = () => { }) => {

return null;
} catch (err) {
console.error(err);
return err.code;
}
};

export const login = async (url, dialogControl, callback = () => { }) => {
export const isAuthLink = url => {
return fb.auth().isSignInWithEmailLink(url);
};

export const login = async (url, dialogControl, callback = () => {}) => {
try {
if (!fb.auth().isSignInWithEmailLink(url)) {
if (!isAuthLink(url)) {
return null;
}

Expand Down Expand Up @@ -91,14 +94,14 @@ export const updateRequest = async (
userId,
requestId,
payload,
callback = () => { }
callback = () => {}
) => {
await retrieveRequest(userId, requestId).update(payload);

callback();
};

export const createRequest = async (userId, request, callback = () => { }) => {
export const createRequest = async (userId, request, callback = () => {}) => {
await fbh.usersCollection
.doc(userId)
.collection("requests")
Expand All @@ -113,7 +116,7 @@ export const createRequest = async (userId, request, callback = () => { }) => {
export const signInWithGoogle = () =>
fb.auth().signInWithRedirect(new fb.auth.GoogleAuthProvider());

export const deleteRequest = async (userId, requestId, callback = () => { }) => {
export const deleteRequest = async (userId, requestId, callback = () => {}) => {
await retrieveRequest(userId, requestId).delete();

callback();
Expand All @@ -122,7 +125,7 @@ export const deleteRequest = async (userId, requestId, callback = () => { }) =>
export const updateUserPhoneNumber = (userId, phoneNumber) =>
fbh.additionalUserInfoCollection.doc(userId).update({ phoneNumber });

export const deleteUser = (userId, callback = () => { }) => {
export const deleteUser = (userId, callback = () => {}) => {
fbh.usersCollection.doc(userId).delete();
fbh.additionalUserInfoCollection.doc(userId).delete();

Expand All @@ -131,7 +134,7 @@ export const deleteUser = (userId, callback = () => { }) => {
callback();
};

export const getDelivered = async (callback = () => { }) => {
export const getDelivered = async (callback = () => {}) => {
const resp = await fb
.firestore()
.collectionGroup("requests")
Expand Down

0 comments on commit 1cb7ac1

Please sign in to comment.