update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
import dns from "node:dns"
|
||||
import * as XLSX from 'xlsx';
|
||||
import CryptoJS from "crypto-js";
|
||||
|
||||
|
||||
export const generateSerialNumber = (index, currentPage, pageSize) => {
|
||||
@@ -218,4 +219,18 @@ export function formatDateToYYYYMMDD(dateString) {
|
||||
|
||||
// Combine the formatted parts
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Encrypt a string
|
||||
export const encryptString = (text) => {
|
||||
const ciphertext = CryptoJS.AES.encrypt(text, import.meta.env.VITE_ROLE_ENCRYPTION_KEY).toString();
|
||||
return ciphertext;
|
||||
};
|
||||
|
||||
// Decrypt a string
|
||||
export const decryptString = (ciphertext) => {
|
||||
const bytes = CryptoJS.AES.decrypt(ciphertext, import.meta.env.VITE_ROLE_ENCRYPTION_KEY);
|
||||
const originalText = bytes.toString(CryptoJS.enc.Utf8);
|
||||
return originalText;
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
import { encryptString } from '../Constants/Constants'
|
||||
|
||||
// Define a base query function with RTK Query
|
||||
// export const baseQuery = fetchBaseQuery({
|
||||
@@ -100,7 +101,7 @@ export const apiSlice = createApi({
|
||||
localStorage.setItem("refreshToken", data?.data?.refresh?.token);
|
||||
// localStorage.setItem('refreshTokenExp', data?.data?.refresh?.expires);
|
||||
localStorage.setItem("accessTokenExp", data?.data?.access?.expires);
|
||||
localStorage.setItem("role", data?.data?.role);
|
||||
localStorage.setItem("role", encryptString(data?.data?.role));
|
||||
} catch (error) {
|
||||
console.error("Login failed:", error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user