Posts

RAZORPAY FRONTEND CODE

 RAZORPAY FRONTEND CODE BUYNOW.JS import React , { useState , useEffect } from "react" ; import { useParams , useNavigate } from "react-router-dom" ; import axios from "axios" ; import { Button } from "reactstrap" ; import { getCurrentUser , getToken , BASE_URL } from "../Components/Auth" ; import Base from "../Components/Base" ; const BuyNowPage = () => {   const { moduleId } = useParams ();   const navigate = useNavigate ();   const [ userId , setUserId ] = useState ( "" );   const [ currentUser , setCurrentUser ] = useState ( null );   const [ phoneNumber , setPhoneNumber ] = useState ( "" );   const [ loading , setLoading ] = useState ( false );   const fixedAmount = 25 ;   useEffect (() => {     const user = getCurrentUser ();     if ( user ) {       setUserId ( user . userId );       setCurrentUser ( user );     }   }, []);...

RAZORPAY CODE BACKEND

Razorpay Integration - CDAC Learning CDAC Learning - Razorpay Backend Integration Date: February 05, 2025 Entity - BuyNow package com.salman.dac.entity; import jakarta.persistence.*; import lombok.*; @Entity @Table(name = "buy_now") @Getter @Setter @NoArgsConstructor @AllArgsConstructor public class BuyNow { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @ManyToOne @JoinColumn(name = "user_id", nullable = false) private User user; @ManyToOne @JoinColumn(name = "module_id", nullable = false) private Module module; private int amount; private String razorpayOrderId; private String orderStatus; private String phno; } Controller - BuyNowController package com.salman.dac.controller; import org.springframework.web.bind.annotation.*; import org.springframework.http.ResponseEntity;...

JWT Authentication with Spring Boot

Image
JWT Authentication with Role-based access in a Spring Boot Introduction This tutorial will guide you through implementing  JWT-based authentication  in a Spring Boot application with role-based access. We’ll also integrate a  React frontend  that allows users to log in and redirects them based on their roles (Admin or User). JWT Authentication Flow The flow of JWT-based authentication involves several steps for secure communication between the user, frontend, and backend. Below is a visual representation of the JWT authentication flow: The flowchart demonstrates how a user logs in, receives a JWT token, stores it in local storage, and sends it with each authenticated request. The backend verifies the token and either grants access or responds with a 401 Unauthorized status if the token is invalid. Backend: Spring Boot Setup Start by creating a Spring Boot application with the following dependencies: Spring Web  for creating REST APIs Spring Security  for ha...
Image
 CDAC LEARNING