Giter Club home page Giter Club logo

colyseus-social's Introduction



Discussion forum

Authentication and Social features for Colyseus
View documentation

Features

  • Authenticate with Facebook
  • Get list of user's friends
  • Get list of user's online friends
  • Friend requests (send, accept, decline)
  • Block user

Hooks

import { hooks } from "@colyseus/social";

hooks.beforeAuthenticate((provider, $setOnInsert, $set) => {
    // assign default metadata upon registration
    $setOnInsert = {
        metadata: {
            coins: 100,
            trophies: 0
        }
    };
});

hooks.beforeUserUpdate((_id, fields) => {
    if (fields['username']) {
        if (fields['username'] === "bad word!") {
            throw new Error("can't have bad words!");
        }
    }
})

Authentication Providers

  • Anonymous
  • Facebook
  • ...more coming soonish!

Environment Variables

  • MONGO_URI: MongoDB connection URI
  • JWT_SECRET: Secure secret string for authentication.

For Facebook:

  • FACEBOOK_APP_TOKEN: Facebook App Token ("appid|appsecret")

For Push Notifications

  • WEBPUSH_SUBJECT - mailto: or URL.
  • WEBPUSH_PUBLIC_KEY - VAPID Public Key
  • WEBPUSH_PRIVATE_KEY - VAPID Private Key

You can generate VAIPD keys using npx web-push generate-vapid-keys

Integration with your Node.js Web Framework

Express

import express from "express";
import socialRoutes from "@colyseus/social/express"

const app = express();
app.use("/", socialRoutes);

app.listen(8080);

TODO's

License

MIT License.

colyseus-social's People

Contributors

chriscauley avatar endel avatar mobyjames avatar tv-t avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

colyseus-social's Issues

Any example?

Is this a separate http service?
I don't understand how to use it.

Any example?

Custom UserID Support

Hi,

I have an authentication system that provide userIDs.

By anonymous login, Instead of generating ID from the server, I would like to use my ID to login into colyseus-social. From what i see in the source-code, I can send "deviceId" or "platform" to the server, is it possible to post an existing ID to the server as well?

`

queryParams["deviceId"] = GetDeviceId();
queryParams["platform"] = GetPlatform();
		var userData = await Request<UserData>("POST", "/auth", queryParams);

		_id = userData._id;
		Username = userData.Username;
		DisplayName = userData.DisplayName;
		AvatarUrl = userData.AvatarUrl;

		FriendIds = userData.FriendIds;
		BlockedUserIds = userData.BlockedUserIds;

		Token = userData.Token;`

Thanks!

OAuth2 support

Hey bit of a feature request but would it be possible to get OAuth2 support for colyseus-social?

Router.use gets object instead of function when requring socialRoutes

Hi -- I seem to be getting an error in importing (rather requiring) because I am node 9.7.1

Here is the error trace that I am getting:
/home/runner/GamesServer/node_modules/express/lib/router/index.js:458
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^

TypeError: Router.use() requires a middleware function but got a Object
at Function.use (/home/runner/GamesServer/node_modules/express/lib/router/index.js:458:13)
at Function. (/home/runner/GamesServer/node_modules/express/lib/application.js:220:21)
at Array.forEach ()
at Function.use (/home/runner/GamesServer/node_modules/express/lib/application.js:217:7)
at Object. (/home/runner/GamesServer/index.js:58:5)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

conflict with express-basic-auth package

node_modules/express-basic-auth/express-basic-auth.d.ts:48:22 - error TS2430: Interface 'IBasicAuthedRequest' incorrectly extends interface 'Request'.
  Types of property 'auth' are incompatible.
    Property '_id' is missing in type '{ user: string; password: string; }' but required in type 'AuthDataInToken'.

48     export interface IBasicAuthedRequest extends Request {
                        ~~~~~~~~~~~~~~~~~~~

  node_modules/@colyseus/social/src/auth.d.ts:6:5
    6     _id: string;
          ~~~
    '_id' is declared here.


Found 1 error.

Registering an user

How would one register a user using email and password? As I can see, there is support only for authorization.

User auth object is empty on Defold Client

I've set up Social going off the docs - I make a login request, and I see the user get generated in MongoDB, but the user never gets back an auth token or anything, the auth table that gets returned is empty (not nil). Am I missing something?

Here's the lua code for making the login call

function NetworkManager:login(username, pw, callback)
	local ip = "ws://127.0.0.1:2567";
	print("Connecting to IP: ", ip);
	self.client = ColyseusClient.new(ip);
	self.client.auth:login({
		email = username,
		password = pw },
		function (err, auth)
			if err == nil then
				print("Auth: ", table.concat(auth));
				callback("SUCCESS")
			else
				callback("FAILED")
			end
		end
	)
end

How to send game invites

Without messaging functionality, how could one go about sending invites and creating parties that join rooms together with colyseus-social?

Unable to connect to mLab MongoDB addon from Heroku

As the title says, I am unable to connect to the mLab MongoDB addon from Heroku. Would be glad to receive any suggestions. My environment variables are as follows:

JWT_SECRET ZSy5CfFW1GiM8xsFtSHA
MONGODB_URI mongodb://heroku_0t3t4std:[email protected]:49433/heroku_0t3t4std
MONGO_URI mongodb://heroku_0t3t4std:[email protected]:49433/heroku_0t3t4std
NODE_OPTIONS --max_old_space_size=20480
NPM_CONFIG_PRODUCTION false

The index.ts:

import http from "http";
import express from "express";
import socialRoutes from "@colyseus/social/express"
import cors from "cors";
import { Server } from "colyseus";
import { monitor } from "@colyseus/monitor";
import GlobalRoom from "./src/room";

const app = express()
app.use(cors());
app.use(express.json())
const server = http.createServer(app);
const gameServer = new Server({
  server,
});
gameServer.define('room', GlobalRoom);

app.use("/", socialRoutes);
app.listen(8080);

// register colyseus monitor AFTER registering your room handlers
/* app.use("/colyseus", monitor()); */

/* const port = Number(process.env.PORT || 2567); */
const port = 7070;
gameServer.listen(port);
console.log(`Listening on ws://localhost:${ port }`)

Logs:

Listening on ws://localhost:7070
2020-04-27T03:15:57.066759+00:00 app[web.1]: (node:23) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
2020-04-27T03:15:57.152939+00:00 app[web.1]: Error connecting to database:  MongoNetworkError: failed to connect to server [ds149433.mlab.com:49433] on first connect [MongoNetworkError: connection timed out
2020-04-27T03:15:57.152941+00:00 app[web.1]: at connectionFailureError (/app/node_modules/mongodb/lib/core/connection/connect.js:406:14)
2020-04-27T03:15:57.152942+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connect.js:294:16)
2020-04-27T03:15:57.152942+00:00 app[web.1]: at Object.onceWrapper (events.js:416:28)
2020-04-27T03:15:57.152943+00:00 app[web.1]: at Socket.emit (events.js:310:20)
2020-04-27T03:15:57.152943+00:00 app[web.1]: at Socket.EventEmitter.emit (domain.js:482:12)
2020-04-27T03:15:57.152944+00:00 app[web.1]: at Socket._onTimeout (net.js:479:8)
2020-04-27T03:15:57.152944+00:00 app[web.1]: at listOnTimeout (internal/timers.js:549:17)
2020-04-27T03:15:57.152945+00:00 app[web.1]: at processTimers (internal/timers.js:492:7) {
2020-04-27T03:15:57.152945+00:00 app[web.1]: name: 'MongoNetworkError',
2020-04-27T03:15:57.152945+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-04-27T03:15:57.152946+00:00 app[web.1]: }]
2020-04-27T03:15:57.152946+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb/lib/core/topologies/server.js:438:11)
2020-04-27T03:15:57.152947+00:00 app[web.1]: at Pool.emit (events.js:310:20)
2020-04-27T03:15:57.152947+00:00 app[web.1]: at Pool.EventEmitter.emit (domain.js:482:12)
2020-04-27T03:15:57.152948+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:561:14
2020-04-27T03:15:57.152949+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:994:11
2020-04-27T03:15:57.152949+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/connect.js:31:7
2020-04-27T03:15:57.152950+00:00 app[web.1]: at callback (/app/node_modules/mongodb/lib/core/connection/connect.js:264:5)
2020-04-27T03:15:57.152950+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connect.js:294:7)
2020-04-27T03:15:57.152951+00:00 app[web.1]: at Object.onceWrapper (events.js:416:28)
2020-04-27T03:15:57.152951+00:00 app[web.1]: at Socket.emit (events.js:310:20)
2020-04-27T03:15:57.152951+00:00 app[web.1]: at Socket.EventEmitter.emit (domain.js:482:12)
2020-04-27T03:15:57.152952+00:00 app[web.1]: at Socket._onTimeout (net.js:479:8)
2020-04-27T03:15:57.152952+00:00 app[web.1]: at listOnTimeout (internal/timers.js:549:17)
2020-04-27T03:15:57.152953+00:00 app[web.1]: at processTimers (internal/timers.js:492:7) {
2020-04-27T03:15:57.152953+00:00 app[web.1]: name: 'MongoNetworkError',
2020-04-27T03:15:57.152954+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-04-27T03:15:57.152954+00:00 app[web.1]: }
2020-04-27T03:16:20.341986+00:00 heroku[web.1]: State changed from crashed to starting
2020-04-27T03:16:20.337781+00:00 heroku[web.1]: State changed from starting to crashed

Add MONGODB_URI also

As I see, colyseus-social checks only for the MONGO_URI environmental variable. It would be better to add also MONGODB_URI so that it will work with the MongoDB addon on Heroku out-of-the-box.

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.