Skip to content

Commit 79c4ccd

Browse files
committed
[CODEBREW] Video 006
1 parent 85eeac9 commit 79c4ccd

File tree

3 files changed

+82
-74
lines changed

3 files changed

+82
-74
lines changed

src/App.vue

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
11
<template>
22
<div id="app">
33
<img alt="Vue logo" src="./assets/logo.png" />
4-
<HelloWorld msg="Welcome to Your Vue.js App" />
4+
<LoginForm @login="login" v-if="!loggedIn" msg="Bitte einloggen" />
5+
<div v-else>
6+
Sie sind eingeloggt
7+
</div>
58
</div>
69
</template>
710

811
<script>
9-
import HelloWorld from "./components/HelloWorld.vue";
12+
import LoginForm from "./components/LoginForm.vue";
1013
import * as fb from "./firebase";
1114
1215
export default {
1316
name: "App",
1417
components: {
15-
HelloWorld,
18+
LoginForm,
19+
},
20+
data() {
21+
return {
22+
loggedIn: false
23+
}
1624
},
1725
18-
mounted() {
19-
/*
20-
fb.auth.createUserWithEmailAndPassword("[email protected]","")
21-
.then((userCredentials) => {
22-
var user = userCredentials.user;
23-
console.log("Newly created user: ",user);
24-
})
25-
*/
26-
let email = "[email protected]";
27-
let pwd = ""
28-
fb.auth.signInWithEmailAndPassword(email,pwd).then((userCredentials) => {
26+
methods: {
27+
login(payload) {
28+
fb.auth.signInWithEmailAndPassword(payload.email,payload.password).then((userCredentials) => {
2929
var user = userCredentials.user;
3030
console.log("Logged in user:",user);
31+
this.loggedIn = true;
3132
}).catch((error) => {
3233
var errorCode = error.code;
3334
var errorMessage = error.message;
3435
console.log("Failed to login: ",errorCode,errorMessage);
36+
this.loggedIn = false;
3537
});
38+
}
39+
},
3640
37-
38-
41+
mounted() {
42+
/*
43+
fb.auth.createUserWithEmailAndPassword("[email protected]","")
44+
.then((userCredentials) => {
45+
var user = userCredentials.user;
46+
console.log("Newly created user: ",user);
47+
})
48+
*/
3949
/*
4050
fb.demoCollection
4151
.doc("pbLh3aRXvxHzNCtp4QKb")

src/components/HelloWorld.vue

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/components/LoginForm.vue

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<div class="hello">
3+
<h1>{{ msg }}</h1>
4+
<form
5+
>
6+
<input type="email" v-model="email" placeholder="Email Adresse">
7+
<br>
8+
<input type="password" v-model="password" placeholder="Passwort">
9+
<br>
10+
<input type="button" value="LOG IN" @click="login">
11+
</form>
12+
</div>
13+
</template>
14+
15+
<script>
16+
export default {
17+
name: 'LoginForm',
18+
props: {
19+
msg: String
20+
},
21+
22+
data() {
23+
return {
24+
email: "",
25+
password: ""
26+
}
27+
},
28+
29+
methods: {
30+
login() {
31+
this.$emit("login", {
32+
email: this.email,
33+
password: this.password
34+
})
35+
},
36+
},
37+
}
38+
</script>
39+
40+
<!-- Add "scoped" attribute to limit CSS to this component only -->
41+
<style scoped>
42+
h3 {
43+
margin: 40px 0 0;
44+
}
45+
ul {
46+
list-style-type: none;
47+
padding: 0;
48+
}
49+
li {
50+
display: inline-block;
51+
margin: 0 10px;
52+
}
53+
a {
54+
color: #42b983;
55+
}
56+
</style>

0 commit comments

Comments
 (0)