Login.vue

This is where the user can login into their account.

import

// Importing Vue components for the NavigationBar and Footer
import NavigationBar from "../reusable-layout/NavigationBar.vue";
import Footer from "../reusable-layout/Footer.vue";
// Importing Axios for making HTTP requests
import axios from "axios";

Above, we are importing the NavigationBar and Footer component which is a reusable layout because navigation bars and footers are usually same for each page so instead of writing it for each page, it's better to write it in one Vue page and import it in each page as components

Next, is the "axios" package which is used to make API call to the backend (Laravel). It is important because this is like the key that allows us to communicate with the backend.

export default

// Exporting the Vue component
export default {}

Inside this is where we define data, methods, computed properties, and lifecycle hooks.

components

// Register the imported components
components: {
  NavigationBar,
  Footer,
}

The components option is used to register and make Vue external components available for use within this component

data

The data method is used to initialize and define the data properties for this component. See the source code to know what each variable is used for.

mounted

This is called mounted lifecycle hook. The mounted hook is called after the component has been added to the DOM, making it a good place to perform initial setup and actions.

To explain what this mounted hook does:

  1. It scrolls the window to the top so the user sees the content at the beginning of the page.

  2. It gets the backend domain from what is defined in the Vuex.

methods

The methods option is used to define methods that can be called or triggered within a Vue component. These methods are typically used to define the behavior and functionality of the component

loginUser

To explain what this loginUser method does:

  1. It sends the username and password inputted by the user to the backend.

  2. If the username and password matches with an account, the ID and username of the user will be saved to the cookie. It will redirect the user to the home page.

  3. If the username and password matches with an account but the account is not verified yet, the user will be alerted with a message.

  4. If the username and password does not match with an account, the user will be alerted with a message.

loginGoogleUser

To explain what this loginGoogleUser method does:

  1. It retrieves an authentication URL which is used to authenticate the user's Google account. It is needed so because the username and password is generated from that Google account.

  2. The authentication URL will be opened in a pop-up window.

  3. Then, the changes that happens in the URL bar of the pop-up window is monitored because after the user has authenticated their account, Google will send a code which is then used to login the user.

  4. After the code has been given by Google, the user ID and username of the user will be saved to the cookie. It will redirect the user to the home page.

loginFacebookUser

To explain what this loginFacebookUser method does:

  1. It retrieves an authentication URL which is used to authenticate the user's Facebook account. It is needed so because the username and password is generated from that Facebook account.

  2. The authentication URL will be opened in a pop-up window.

  3. Then, the changes that happens in the URL bar of the pop-up window is monitored because after the user has authenticated their account, Facebook will send a code which is then used to login the user.

  4. After the code has been given by Facebook, the user ID and username of the user will be saved to the cookie. It will redirect the user to the home page.

togglePasswordVisibility

To explain what this togglePasswordVisibility method does:

  1. It hide or shows the content of the password input field.

Last updated