1.0.0 • Published 5 years ago

ad-auth-system v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

The auth-system package from Afro Develops Team.

This package only store user information but doesn't run sessions on our server.

The User's informations

Since we are using Mongodb, the UserSchema is defined like so:

UserSchema = {
	username: { type: String, required: true },
	email: { type: String, required: true, unique: true },
	password: { type: String, required: true },
	birth_date: { type: String, required: true },
	first_name: String,
	last_name: String,
	avatar: String,
	created_at: { type: Date, default: Date.now() },
	updated_at: { type: Date, default: Date.now() }
}

Functions available

The auth-system is a CRUD api, we can separate functions in 5 groups.

  1. Create
    • createUser
  2. Read
    • getUsers (Get All Users)
    • getOneWithMail (Fetching one user knowing his mail address)
    • getOneWithUsername (Fetching one user knowing his username)
  3. Update
    • updateWithMail (Updating one user using his mail address)
    • updateWithUsername (Updating one user using his username)
  4. Delete

    • deleteWithMail (Deleting one user using his mail address)
    • deleteWithUsername (Deleting one user using his username)

Usage's example for each function

createUser

This function takes a User as parameter.

// Creating a new user on Nodejs.
router.post('/new', async (req, res) => {
	try {
		const { data } = await createUser(req.body)
		return res.send(data)
	} catch({ message }) {
		return res.send(message)
	}
})

getUsers

This function retrieves all the users in the database.

// Fetching all users from a nodejs server.
router.get('/all', async (req, res) => {
	try {
		const { data } = await getUsers()
		return res.send(data)
	} catch({ message }) {
		return res.send(message)
	}
});
1.0.0

5 years ago