JS class refactor for user login

This commit is contained in:
MathewFrancis 2025-05-28 14:21:06 +05:30
parent 8b8b0f1b96
commit 53e1fa758d
46 changed files with 64 additions and 15 deletions

View File

@ -54,7 +54,7 @@ services:
react_app:
image: mathewfrancisv/cezen_react:v1.0.0
image: mathewfrancisv/cezen_react:v2.0.0
container_name: react_cezenpbx
restart: always
working_dir: /app

0
MySQL_conf_pbx/test1/reactcezenpbx/.gitignore vendored Normal file → Executable file
View File

0
MySQL_conf_pbx/test1/reactcezenpbx/README.md Normal file → Executable file
View File

0
MySQL_conf_pbx/test1/reactcezenpbx/eslint.config.js Normal file → Executable file
View File

0
MySQL_conf_pbx/test1/reactcezenpbx/index.html Normal file → Executable file
View File

0
MySQL_conf_pbx/test1/reactcezenpbx/package-lock.json generated Normal file → Executable file
View File

0
MySQL_conf_pbx/test1/reactcezenpbx/package.json Normal file → Executable file
View File

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

0
MySQL_conf_pbx/test1/reactcezenpbx/public/file.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

0
MySQL_conf_pbx/test1/reactcezenpbx/public/lite1.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

0
MySQL_conf_pbx/test1/reactcezenpbx/public/vite.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

0
MySQL_conf_pbx/test1/reactcezenpbx/src/App.css Normal file → Executable file
View File

0
MySQL_conf_pbx/test1/reactcezenpbx/src/App.jsx Normal file → Executable file
View File

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 748 B

After

Width:  |  Height:  |  Size: 748 B

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -1,4 +1,4 @@
import { userLogin } from "../../http_routs/userHttp";
import { userLoginAndResp } from "../../http_routs/userHttp";
export default function LogIn() {
function logInFunction(event) {
@ -9,7 +9,7 @@ export default function LogIn() {
const data = Object.fromEntries(formData.entries());
console.log(data);
userLogin(data.user_name, data.password);
userLoginAndResp(data.user_name, data.password);
}
return (

View File

View File

@ -33,20 +33,69 @@ export async function createUserNewAdmin(signUpObject = {}) {
*/
//user login data
export async function userLogin(username, password) {
// export async function userLogin(username, password) {
// //make an http get request for userLogin login
// const loginResp = await fetch(`${socket}/open/login`, {
// method: `GET`,
// headers: basicAuthCredentialsBuilder(username, password),
// credentials: "include", // <-- VERY IMPORTANT to get the JWT cookie from the backend
// });
// const resData = await loginResp.json();
// console.log("response data");
// console.log(resData);
// return loginResp;
// }
// //common basic auth header builder
// function basicAuthCredentialsBuilder(username, password) {
// //builds the appropriate format for basic auth
// return {
// Authorization: "Basic " + window.btoa(username + ":" + password),
// };
// }
export async function userLoginAndResp(username, password) {
//make an http get request for userLogin login
const loginResp = await fetch(`${socket}/open/login`, {
method: `GET`,
headers: basicAuthCredentialsBuilder(username, password),
credentials: "include", // <-- VERY IMPORTANT
});
const auth = new authenticationBuilder(socket);
return auth.userLogin(username, password);
}
//common basic auth header builder
function basicAuthCredentialsBuilder(username, password) {
//builds the appropriate format for basic auth
return {
Authorization: "Basic " + window.btoa(username + ":" + password),
};
/**
* This class helps the user login
*/
class authenticationBuilder {
#socketURL = "";
constructor(socketURL) {
this.#socketURL = socketURL;
}
async userLogin(username, password) {
//make an http get request for userLogin login
const loginResp = await fetch(`${this.#socketURL}/open/login`, {
method: `GET`,
headers: this.#basicAuthCredentialsBuilder(username, password),
credentials: "include", // <-- VERY IMPORTANT to get the JWT cookie from the backend
});
const resData = await loginResp.json();
console.log("response data");
console.log(resData);
return loginResp;
}
#basicAuthCredentialsBuilder(username, password) {
//builds the appropriate format for basic auth
return {
Authorization: "Basic " + window.btoa(username + ":" + password),
};
}
}

0
MySQL_conf_pbx/test1/reactcezenpbx/src/index.css Normal file → Executable file
View File

0
MySQL_conf_pbx/test1/reactcezenpbx/src/main.jsx Normal file → Executable file
View File

0
MySQL_conf_pbx/test1/reactcezenpbx/vite.config.js Normal file → Executable file
View File