CompSci Blogs

August 2023 to June 2024

View the Project on GitHub sfremy/csablog

22 January 2024

SASS Javascript Login and Signup Page

by

What exactly is SASS?

1. Why use SASS for your Javascript Login and Signup Page?

Variables in SASS:

$primary-color: #3498db;
body {
  background-color: $primary-color;
}
  Cell In[1], line 1
    $primary-color: #3498db;
    ^
SyntaxError: invalid syntax

Mixins for Reusable Styles:

@mixin button-styles {
    background-color: $primary-color;
    color: #fff;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
  }
  button {
    @include button-styles;
  }  

Nesting in SASS:

nav {
    background-color: $primary-color;
    ul {
      list-style: none;
      li {
        display: inline-block;
        margin-right: 10px;
        a {
          color: #fff;
          text-decoration: none;
        }
      }
    }
  }  

JavaScript Integration

Handling Asynchronous Requests:

async function loginUser(username, password) {
    // Asynchronous logic using Fetch API
  }  

Fetch API:

fetch('https://api.example.com/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ username: 'user', password: 'pass' }),
});

Sending POST Requests:

async function loginUser(username, password) {
    const response = await fetch('https://api.example.com/login', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ username, password }),
    });
  
    const data = await response.json();
    // Handle response data
  }  

Error Handling for HTTP Status Codes:

if (response.ok) {
    // Successful login logic
  } else if (response.status === 401) {
    // Handle unauthorized access
  } else if (response.status === 403) {
    // Handle forbidden access
  } else if (response.status === 404) {
    // Handle not found
  }  
'https://drishyamody.github.io/DJAKTri2//2023/01/22/SASS_Javascript_Login.html'
tags: