Skip to content

This repo explains about creation of server using nodejs and api through fastify, postgres is used as database with local auth and google oauth implementation

Notifications You must be signed in to change notification settings

rojandahal/node-fastify-postgres

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node-Fastify API with postgres

This project was bootstrapped with Fastify-CLI.

Clone this repo using:
git clone https://github.com/rojandahal/node-fastify-postgres.git

Different feature implementation in Branch

-git checkout feature/local-auth : Implements local authentication with postgres with username and password.

-git checkout feature/session-auth : Implements session in local authentication and stores the session in cookies.

-git checkout feature/oauth-google : Extends feature/session-auth and implements "Sign in with google" and stores session and also implements creation of task and fetching of task with user verification improved for both local and OAuth.

Installation

Install dependencies in app with npm

  npm install

Available Scripts

In the project directory, you can run:

npm run dev

To start the app in dev mode.
Open http://localhost:3000 to view it in the browser.

npm start

For production mode

npm run test

Run the test cases.

Learn More

To learn Fastify, check out the Fastify documentation.

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

API_VERSION=
SECRET_KEY=
SESSION_SECRET=
GOOGLE_OAUTH_CLIENT_ID=
GOOGLE_OAUTH_CLIENT_SECRET=
GOOGLE_OAUTH_REDIRECT=
baseURL=

API Reference

Signup

  POST /api/v1/signup
Body Type Description
email string Required
username string Required, Unique
password string Required

Login

  POST /api/v1/login
Body Type Description
username string Required
password string Required

Logout

  POST /api/v1/logout
Header Type Description
token string Required. The token of logged-in user

Get all Users

  GET /api/v1/users/
Header Type Description
token string Required. The token of logged-in user

Get Single User

  GET /api/v1/users/:id
Parameter Type Description
id string Required. The id of the user
token (Header) string Required. The token of logged-in user

Update a User

  POST /api/v1/users/:id
Body Type Description
username string Required. The new username of the user
Parameter Type Description
id string Required. The id of the user
token (Header) string Required. The token of logged-in user

Delete a User

  POST /api/v1/users/:id
Parameter Type Description
id string Required. The id of the user
token (Header) string Required. The token of logged-in user

Sign in with Google

  GET /api/v1/login/google

Create Task

  POST /api/v1/tasks/
Body Type Description
title string Required. The title of task
description string The description of task
status string The status of task

Get a Task

  GET /api/v1/users/:id
Header Type Description
token string Required. The token of logged-in user

About

This repo explains about creation of server using nodejs and api through fastify, postgres is used as database with local auth and google oauth implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published