week3.3 jwt and auth recape

const express = require("express");
const mongoose = require("mongoose");
const app = express();
app.use(express.json())
// const { string } = require("zod");

mongoose.connect("mongodb+srv://luciferdk:noNQzfSoBo6C56GH@cluster2.c277dmn.mongodb.net/bobo");

const User = mongoose.model('Users', { name: String, email: String, password: String });

app.post("/signup", async function(req, res) {
    const username = req.body.username;
    const password = req.body.password;
    const name = req.body.name;


    const existingUser = await User.findOne({email:username});
    if (existingUser) {
        return res.status(400).send("Username Already exists");
    }

    const user = new User({
        name: name,
        email: username,
        password: password
});

user.save();

res.json({
    msg: "User Create Successfully"
})
})


//

const jwt = require("jsonwebtoken");

// decode, derify, generate

const value = {
    name : "ahrkirat",
    accountNumber:123123123
}

//jwt
const tokens = jwt.sign(value, "hindenSecretThatWillOnlyKnowBank");
console.log(tokens);

// this token has been generated using this secret, and hence this token can only be verified using this secret.
// this is your check book


Comments

Popular posts from this blog

CyberSecurity

VERTICAL SCALING 💋

prisma using in project idx 13.3