Code Monkey home page Code Monkey logo

altv-os-auth's Introduction

Open Source - Auth / Login for alt:V

❤️ Become a Sponsor of my Open Source Work

⌨️ Learn how to script for alt:V

💡 Need a Roleplay Script? Try Athena!

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

If you're looking for a Discord login system where you do not store emails, passwords, etc. Try out the alt:V Discord Auth solution.

Quick Install (alt:V Resource Installer)

More info here: https://github.com/stuyk/altv-pkg

# Install alt:V Installer
npm install -g altv-pkg
# Install with alt:V Installer
altv-pkg i stuyk/altv-os-auth

Make sure to run the script after answering questions.

Setting Up Configuration

Create a file in your main directory called config.json.

Edit this file with any notepad program, ide, etc.

Add the following parameters to link up to your Mongo Database.

{
    "db_url": "mongodb://localhost:27017",
    "db_database": "altv",
    "db_collections": ["accounts"],
    "db_username": null,
    "db_password": null
}

db_url is the URL of your MongoDB database. If on windows leave as localhost.

db_database is the name of the database where it will create a collection called accounts.

db_username is completely optional. Recommended in a production environment.

db_password 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 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}`);
}

altv-os-auth's People

Contributors

stuyk avatar tardigrde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

altv-os-auth's Issues

Can't interact with the auth window

Hi!

First of all thanks for this package, as well as all the killer packages you created in order to ease alt:v development!

I have a problem with the authentication. I cloned your repository, installed deps, and put the example snippets into your quickstart project. Here is the code:

alt.on('playerConnect', playerConnect);

function playerConnect(player) {
    alt.log(`${player.name} has connected to the server.`);

    showAuthWindow(player);

    alt.on("auth:Done", exitAuthWindow);
    
    alt.emitClient(player, 'chat:Init');
    const randomModelNumber = Math.floor(Math.random() * DEFAULT_CONFIG.RANDOM_PLAYER_MODELS.length);
    const randomModel = DEFAULT_CONFIG.RANDOM_PLAYER_MODELS[randomModelNumber];
    const randomPosition = randomPositionAround(DEFAULT_CONFIG.SPAWN, DEFAULT_CONFIG.SPAWN_RANGE);

    // Set Model, Set Spawn, Send Message
    player.model = randomModel;
    player.spawn(randomPosition.x, randomPosition.y, randomPosition.z, 0);
    player.send(`Welcome to the server!`);
}
function showAuthWindow(player) {
  alt.emitClient(player, "auth:Open");
  alt.log(`${player.name} has connected!`);
}

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

When I open the client, the auth window is shown, then I immediately get this: WARNING message:

[19:10:20] Player has connected!
[19:10:20][Warning] Event handler at base:file:///C:/codeing/gta/resources/base/server/events/playerConnect.js:7 was too long 13ms

Is this have to be awaited? I'm, not totally sure if this should be syncronous or async?

But the real problem of mine is that I cannot interact with the auth window. I can't click and type in the fields, nor can I click any of the buttons.

Can you give me a hint, what am I doing wrong?

Thanks in advance!

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.