This project is an enhanced authentication system backend API built with Node.js, featuring a new functionality that allows users to set their profiles as public or private. Admin users can view both public and private profiles, while normal users can only access public profiles.
- User registration and login
- OAuth login with Google
- Profile management (view, edit, and upload photo)
- Public/private profile settings
- Admin access to all profiles
- Normal user access to public profiles
- Node.js
- Express.js
- MongoDB
- Mongoose
- Passport.js
- JWT (JSON Web Tokens)
-
Clone the repository:
git clone https://github.com/Atmalviya/Auth_api.git cd yourrepository -
Install dependencies:
npm install
Create a .env file in the root of the project and add the following variables:
MONGO_URI=mongodb+srv://Atmalviya:ATV2malviya@cluster0.2dnnddb.mongodb.net/
JWT_SECRET=ATV2@malviya
GOOGLE_CLIENT_ID=192495763798-38cc9362hfvbkbglabum4bnbarslf0u3.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=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To start the server:
npm run startEndpoint:
POST /api/users/registerRequest Body:
{
"name": "User Name",
"email": "user@example.com",
"password": "userpassword"
}
POST /api/users/loginRequest Body:
{
"email": "user@example.com",
"password": "userpassword"
}
GET /api/users/auth/googleFollow the Google login flow. On successful login, you will be redirected to the home page.
GET /api/users/profileHeaders:
Authorization: Bearer <your_jwt_token>PUT /api/users/profileHeaders:
Authorization: Bearer <your_jwt_token>Request Body:
{
"name": "Updated Name",
"email": "updated@example.com",
"password": "newpassword",
"photo": "new_photo_url",
"bio": "new bio",
"phone": "new phone",
"isPublic": true
}
GET /api/users/publicGET /api/usersHeaders:
Authorization: Bearer <your_admin_jwt_token>Hey! I'm Atul Malviya, a software developer and Computer Science graduate from Jabalpur Engineering College. Currently, I'm gaining valuable experience as a Software Developer Trainee at Opensense Labs. Apart from coding, I've served as the TPO of my college and have a passion for karate, having represented India and won three national gold medals. Let's connect and code together! 🚀