Skip to content

Commit

Permalink
mobile app sign up api added
Browse files Browse the repository at this point in the history
  • Loading branch information
kamadi2000 committed Oct 5, 2023
1 parent 98f52fd commit 8c466d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions backend/src/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,38 @@ exports.loginApp = async (req, res) => {
}
};

exports.signUpApp = async (req, res) => {
try {
// Extract user information
const { email, password, name } = req.body;
const user = await User.findOne({ email })
if (user) {
console.log("User already has an account")
}else{
const saltRounds = 10; // Adjust
const hashedPassword = await bcrypt.hash(password, saltRounds);
// Create a new user
const user = new User({ email, hashedPassword, name });
await user.save();

const token = jwt.sign({ name: user.name, isVerified: user.isVerified }, process.env.SECURITY_KEY, { expiresIn: '5hour' });
return res.header("x-auth-token", token).status(201).json({token});
}








} catch (error) {
console.log('hi')
console.error(error);
res.status(500).json({ error: 'Signup failed' });
}
};


exports.googleLogin = async (req , res) => {
return googleLoginBase(req,res, true)
Expand Down
1 change: 1 addition & 0 deletions backend/src/routes/authRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ router.post('/signup', authController.signup);
router.post('/login', authController.login);
router.post('/googleLogin',authController.googleLogin)
router.post('/loginApp', authController.loginApp);
router.post('/signUpApp',authController.signUpApp)
router.post('/facebooklogin',authController.facebooklogin);
router.post('/logout', authController.logout);

Expand Down

0 comments on commit 8c466d9

Please sign in to comment.