diff --git a/.env b/.env new file mode 100644 index 0000000000000000000000000000000000000000..6bded6386c5adf03bd7d593f5f016875b3040d25 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VUE_APP_BASEURL="http://65.108.62.223:3000/api/" diff --git a/src/components/LoginForm.vue b/src/components/LoginForm.vue index 2c66de7f90eaca49c83d8f5e6bd357eef5c742ac..78824a80b8682129dcda2375d419766b7ff9a22f 100644 --- a/src/components/LoginForm.vue +++ b/src/components/LoginForm.vue @@ -1,57 +1,4 @@ <template> - <!--<div> - <v-col align="center" justify="space-around"> - <v-img - max-width="45%" - :src="require('../assets/logo3.svg')" - align="center" - ></v-img> - </v-col> - - <v-form ref="form" v-model="valid" lazy-validation> - <v-col> - <v-text-field - v-model="user.email" - :rules="emailRules" - label="E-mail" - required - ></v-text-field> - </v-col> - - <v-col align="right"> - <v-text-field - v-model="user.password" - :append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'" - :rules="[rules.required, rules.min]" - :type="showPassword ? 'text' : 'password'" - name="input-10-1" - label="Password" - counter - @click:append="showPassword = !showPassword" - ></v-text-field> - - <div class="text-decoration-underline mt-n4 mr-10">Glemt passord</div> - </v-col> - - <v-col align="center" justify="space-around"> - <v-btn - :disabled="!valid" - color="success" - class="mb-4 mt-4" - width="50%" - height="40px" - @click="loginClicked" - > - Logg inn - </v-btn> - - <div> - <a href="/" class="text-decoration-none">Ny bruker</a> - </div> - </v-col> - </v-form> - </div>--> - <div class="m-6" :class="{ error: v$.user.email.$errors.length }"> <div class="mb-6"> <label @@ -69,10 +16,7 @@ /> <!-- error message --> - <div - v-for="(error, index) of v$.user.email.$errors" - :key="index" - > + <div v-for="(error, index) of v$.user.email.$errors" :key="index"> <div class="text-red-600 text-sm" v-show="showError" id="emailErrorId"> {{ error.$message }} </div> @@ -98,7 +42,11 @@ v-for="(error, index) of v$.user.password.$errors" :key="index" > - <div class="text-red-600 text-sm" v-show="showError" id="passwordErrorId"> + <div + class="text-red-600 text-sm" + v-show="showError" + id="passwordErrorId" + > {{ error.$message }} </div> </div> @@ -113,11 +61,14 @@ <button @click="loginClicked" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" - :disabled="notValid" > Logg inn </button> </div> + + <div> + <label>{{ response }}</label> + </div> </template> <script> @@ -163,6 +114,8 @@ export default { password: "", }, + response: '', + showPassword: false, valid: true, showError: false, @@ -172,7 +125,7 @@ export default { ], rules: { required: (value) => !!value || "Required.", - min: (v) => v.length >= 8 || "Min 8 characters", + min: (v) => v.length >= 0 || "Min 8 characters", }, }; }, @@ -181,12 +134,31 @@ export default { async loginClicked() { console.log(this.user.email + " " + this.user.password); this.showError = true; + + this.v$.user.email.$touch(); + if (this.v$.user.email.$invalid) { + console.log("Invalid, avslutter..."); + return; + } + + console.log("videre!"); + const loginRequest = { email: this.user.email, password: this.user.password, }; + + console.log("før"); + + console.log("env: " + process.env.VUE_APP_BASEURL); + const loginResponse = await doLogin(loginRequest); + + console.log("respons" + loginResponse); + + this.response = loginResponse.data; + if (loginResponse === "Failed login") { this.message = "kunne ikke logge inn"; this.$store.commit("logout"); diff --git a/src/utils/apiutil.js b/src/utils/apiutil.js index 773bd8d67e484a1f42d371339b5a46ce757a9347..392cdac50790000e21b7f405fd5be4b8a80a939e 100644 --- a/src/utils/apiutil.js +++ b/src/utils/apiutil.js @@ -2,8 +2,12 @@ import axios from "axios"; export function doLogin(loginRequest) { return axios - .post(`http://65.108.62.223:3000/api/login/authentication`, loginRequest) + .post(process.env.VUE_APP_BASEURL + 'login/authentication', loginRequest) .then((response) => { return response.data; - }); + }) + .catch((error) => { + console.log(error.response); + return error.response; + }); }