Skip to content

Authentication by express and mongoose database for sign up and sign in and see post after authentication. Also post the user data in post 'user': {} by take ref from user. and get by using populate 'user'.

Notifications You must be signed in to change notification settings

Satyamall/Backend-Authentication-_using_express-mongoose-and-see_post_after_authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backend-Authentication-_using_express-mongoose-and-see_post_after_authentication

Authentication by express and mongoose database for sign up and sign in and see post after authentication. Also post the user data in post 'user': {} by take ref from user. and get by using populate 'user'.

ref:- take reference from collections using like below:

const postSchema = new mongoose.Schema({
    title: {type: String, required: true},
    body: {type: String, required: true},
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "authUsers",
        required: true
    }
},
{ timestamps: true }
);

populate:- take the populate from schema like : -

router.get("/", protect, async (req,res)=>{
    try{

        const posts = await Post.find({}).populate("user");
        return res.status(200).json({data: posts});
    }
    catch(err){
        return res.status(500).json({status: "failed", message: "Something went wrong!"});
    }
});

Postman Picture for post using ref of user and get by using populate from post populte('user'):-

Screenshot (283)

Screenshot (284)

About

Authentication by express and mongoose database for sign up and sign in and see post after authentication. Also post the user data in post 'user': {} by take ref from user. and get by using populate 'user'.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published