MonsterTaerAttO / altv-os-auth

alt:V Login system with built in MongoDB and Vue

Home Page:https://stuyk.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Open Source - Auth / Login for alt:V

Created by Stuyk (Trevor Wessel)

❤️ Please support my open source work by donating. I'm here to provide general context for complicated procedures for you new developers. ❤️

https://github.com/sponsors/Stuyk/

⭐ This repository if you found it useful!


Description

This repository provides an easy way to authenticate users into your database through the alt:V event emitters. Which basically means... put data in get data out in your other resources. This provides a simple decoupled method to authenticate your users and get an identifier through other events.

Setting Up Environment Variables

Create a file in your main directory called .env. Edit this file with any notepad program, ide, etc. Add the following parameters to link up to your Mongo Database.

MONGO_URL=mongodb://localhost:27017
MONGO_DB=os-auth
# MONGO_USER=username
# MONGO_PASS=pass

MONGO_URL is the URL of your MongoDB database. If on windows leave as localhost. MONGO_DB is the name of the database where it will create a collection called accounts. MONGO_USER is completely optional. Recommended in a production environment. MONGO_PASS is completely optional. Recommended in a production environment.

Installing Dependencies / Installation

I cannot stress this enough. Ensure you have NodeJS 13+ or you will have problems.

In your base gamemode directory where your .exe or alt-server files are. Simply run these commands.

npm install chalk
npm install dotenv
npm install pbkdf2
npm install simplymongo
npm install sjcl

After simply add the name of this resource to your server.cfg resource section. Then simply clone this repository into your main server resources folder.

cd resources
git clone https://github.com/Stuyk/altv-os-auth

Ensure your package.json includes this property:

"type": "module"

Events & Triggering Authentication

You have to hookup some general events to your gamemode to get things working. Here's what you have to do.

Show the Authentication Window

Server-Side

alt.on('playerConnect', showAuthWindow);

function showAuthWindow(player) {
    alt.emitClient(player, 'auth:Open');
    console.log(`${player.name} has connected!`);
}

Close the Authentication Window after Authenticating

This event specifically comes with some data from the player. Such as their account database id, username, email, etc.

Server-Side

alt.on('auth:Done', exitAuthWindow);

function exitAuthWindow(player, id, username, email) {
    alt.emitClient(player, 'auth:Exit');
    console.log(`${player.name} has authenticated!`);
    console.log(`Their Database ID is: ${id}`);
}

About

alt:V Login system with built in MongoDB and Vue

https://stuyk.com/

License:The Unlicense


Languages

Language:JavaScript 58.1%Language:HTML 21.1%Language:CSS 20.8%