Giter Site home page Giter Site logo

satyamall / backend-authentication-_using_express-mongoose-and-see_post_after_authentication Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 52 KB

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'.

Shell 0.39% JavaScript 99.61%
expressjs mongoose express-validator cors middleware validation populate jason-web-tokens bcrypt dotenv

backend-authentication-_using_express-mongoose-and-see_post_after_authentication's Introduction

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)

backend-authentication-_using_express-mongoose-and-see_post_after_authentication's People

Contributors

satyamall avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.