Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added backend/dist/index.html
Empty file.
4 changes: 2 additions & 2 deletions backend/env.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const EMAIL = "pramanickdebesh@gmail.com";
export const PASSWORD = "hzgtirhzoqsdeltq";
export const EMAIL = "mail@mail.com";
export const PASSWORD = "passcode";
35 changes: 35 additions & 0 deletions backend/functions/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// import express from "express";
// import ServerlessHttp from "serverless-http";

// const app = express();

// app.get('/.netlify/functions/api', (req,res)=>{
// return res.json({"message":"Hello"});
// });

import express from 'express';
import ServerlessHttp from "serverless-http";
import cookieParser from 'cookie-parser';
import cors from 'cors';
import { router } from '../routes/routes.mjs';

const app = express();
app.use(cookieParser());
app.use(cors({
origin: 'http://localhost:3000', // replace with your React app origin
credentials: true,
}));
// const PORT = process.env.PORT || 6541;

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/.netlify/functions/api' ,router);



const handlers = ServerlessHttp(app);

export const handler = async(event, context)=>{
const result = await handlers(event, context);
return result
}
40 changes: 32 additions & 8 deletions backend/logics/Login/login.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GraphQLClient} from 'graphql-request';
import { LoginQuery } from './query.mjs';
import jwt from 'jsonwebtoken';
import bcrypt from 'bcrypt';
// import bodyParser from "body-parser";

const login = new LoginQuery();
Expand Down Expand Up @@ -32,23 +33,46 @@ const client = new GraphQLClient(hasuraEndpoint, {
},
});

// http://host.docker.internal:8888


export class LoginUser{
async login(req, res){
try{
// console.log(req.body)
const {email, password} = req.body;
const data = await client.request(login.loginUser(email, password),{});
const {email, password} = req.body.input.input;




const data = await client.request(login.loginUser(),{email});

if (data.user.length === 0) {
// User not found
return res.status(401).json({ message: false });
}

const user = data.user[0];
console.log("This is user data: ", user);

// Compare the entered password with the hashed password
const passwordMatch = await bcrypt.compare(password, user.password);

console.log("Password Match: ", passwordMatch)
if (!passwordMatch) {
// Passwords do not match
return res.status(401).json({ message: false });
}

const token = generateJwtToken();
// console.log(data);
console.log("Data for the same: ",data);
// res.json(data);
res.status(200).json(
res.json(
{
"message":"Welcome User",
"uuid":data.kalenview_by_pk.uuid,
"first_name":data.kalenview_by_pk.first_name,
"last_name":data.kalenview_by_pk.last_name,
"message": true,
"uuid": user.uuid,
"first_name": user.first_name,
"last_name": user.last_name,
"token": token // Include the JWT in the response
});
}catch (error) {
Expand Down
15 changes: 8 additions & 7 deletions backend/logics/Login/query.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export class LoginQuery {
loginUser(email, password){
loginUser(){
return `
query MyQuery {
kalenview_by_pk(email: "${email}", password: "${password}") {
uuid
first_name
last_name
}
query getUserByEmail($email: String!) {
user: kalenview(where: {email: {_eq: $email}}) {
first_name
last_name
uuid
password
}
}
`
};
}
13 changes: 12 additions & 1 deletion backend/logics/Register/query.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
export class RegisterEventQuery{
registerUser(){
return `

mutation ($email: String!, $hashedPassword: String!, $firstName: String!, $lastName: String!, $company: String!, $role: String!) {
insert_kalenview_one(object: {
email: $email,
password: $hashedPassword,
first_name: $firstName,
last_name: $lastName,
company_name: $company,
company_role: $role
}) {
uuid
}
}
`;
}
}
17 changes: 12 additions & 5 deletions backend/logics/Register/registerUser.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GraphQLClient} from 'graphql-request';
import { RegisterEventQuery } from './query.mjs';
import bcrypt from 'bcrypt';
// import bodyParser from "body-parser";

const new_user = new RegisterEventQuery();
Expand All @@ -18,18 +19,24 @@ const client = new GraphQLClient(hasuraEndpoint, {

export class CreateUser{
async create_user(req, res){
const { email, password, firstName, lastName, company, role } = req.body;
console.log(req.body.input.input);
const { email, password, firstName, lastName, company, role } = req.body.input.input;
console.log(email, password, firstName, lastName, company, role);

try {

const saltRounds = 10;
const hashedPassword = await bcrypt.hash(password, saltRounds);

const data = await client.request( new_user.registerUser(),{
email, password, firstName, lastName, company, role
email, hashedPassword, firstName, lastName, company, role
});

console.log(data);
console.log(data.insert_kalenview_one.uuid);


// res.json(data);
res.status(200).json({success: true});
// res.json(data.insert_kalenview_one.uuid);
res.status(200).json({uuid:`${data.insert_kalenview_one.uuid}`});
} catch (error) {
console.error('Failed to create user:', error);
res.json({ Notsuccess: false });
Expand Down
2 changes: 2 additions & 0 deletions backend/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
functions = "functions"
Loading