Posts

Demystifying JWT Token Expiration: Theory and Best Practices in Angular

Introduction: In the world of web development, security is paramount. JSON Web Tokens (JWT) have become a popular method for securely transmitting information between parties. One crucial aspect of JWTs is their expiration, which ensures that tokens don’t remain valid indefinitely, mitigating the risk of unauthorized access. In this article, we’ll delve into the theory behind JWT token expiration and explore best practices for implementing expiration checks effectively. Understanding JWT Token Expiration: JWTs consist of three parts: a header, a payload, and a signature. The payload contains the claims, which are statements about an entity (typically the user) and additional data. One of these claims can be the token’s expiration time, denoted by the “exp” claim. The expiration time is a Unix timestamp that specifies when the token should no longer be considered valid. When a JWT is issued, the expiration time is set based on the desired duration of vali...

Harnessing the Magic of Base64: Converting Images and PDFs with Ease

In today’s digital landscape, the ability to seamlessly handle multimedia files is crucial for web developers. Enter Base64 encoding — a powerful technique that transforms binary data into text strings, opening the door to a myriad of possibilities. In this tutorial, we’ll explore how to leverage Base64 encoding to convert images and PDFs into easily manageable strings. Using Angular and JavaScript, we’ll unravel the mysteries of file manipulation, empowering you to integrate this functionality into your web applications effortlessly. HTML file <input type="file" accept="image/*" (change)="imageChanged($event)"> <input type="file" accept=".pdf" (change)="pdfChanged($event)"> Function to convert image to base 64 as promise public imageToBase64Promise(event: any): Promise<string> { const promise = new Promise<string>((resolve, re...

Custom Validator to match Password and Confirm Password in Angular

Creating a custom validator to match the password and confirm password fields in an Angular form is a common requirement for many applications. Introduction to Custom Validators: Custom validators in Angular allow you to extend the default validation capabilities and create specific rules tailored to your needs. They can be used for various purposes, such as ensuring passwords match, validating email formats, or checking for forbidden values. Signup Model import { FormControl } from "@angular/forms"; export interface SignupFormModel{ name: FormControl<string | null>; email: FormControl<string | null>; password: FormControl<string | null>; confirmPassword: FormControl<string | null>; } Ts File public signupFormGroup: FormGroup<SignupFormModel> = new FormGroup<SignupFormModel>({ name: new FormControl(null, [Validators.required]), em...

How to Avoid Page Changes When You Have Unsaved Changes in Angular

Introduction: Navigating away from a webpage with unsaved changes can lead to data loss and frustration. In this guide, we’ll explore effective methods to prevent page changes when you have unsaved changes in an Angular application. Whether you’re a developer or a user, understanding these techniques will help you safeguard your work.  Why Preventing Page changes with unsaved changes matter..? Understanding the importance of preventing accidential navigation can save your time and prevent the loss of valuable information. When working on forms, editing documents, or entering data in Angular application, ensuring your changes are saved before leaving the page is crucial. So, to  avoid page change when we have unsaved changes we can use canDeactivateFn() method of route guard. Navigating away from a webpage with unsaved changes can lead to data loss and frustration. In this guide, we'll explore effective methods to prevent page changes when you have unsaved changes in...

Creating Generic Dialogue Box in Angular 16

Image
  So, in this post we will see how to create generic dialogue box in angular with the help of ngx-bootstrap. Video Link : So, our intution is that, we will create a separate component for generic dialogue box, so that we can use it in our whole application. Step 1:  install the ngx-bootstrap, run this command in CLI to install it “ ng add ngx-bootstrap ”. You can read more about ngx-bootstrap, just  click  here. Step 2:  Create a component named “ generic-dialog-box ” inside app component. After creating this component your file structure would look like this. Now, in the ‘ app.module.ts’  import  ‘ModalModule’  from ‘ ngx-bootstrap/modal ’. like this,  import { ModalModule } from ‘ngx-bootstrap/modal’;  and add  ModalModule.forRoot()  in the imports array of module.ts.file, Generic Dialog Box Compone...