jkomoros / boardgame

An in-progress framework in golang to easily build boardgame Progressive Web Apps
Apache License 2.0
31 stars 4 forks source link

how to replace firebase with other real time db ? #512

Open wadelee1986 opened 6 years ago

wadelee1986 commented 6 years ago

I am from China, can't connect to google firebase server.

jkomoros commented 6 years ago

Firebase is actually not used for data storage, but rather only for user authentication, and as a simple static-file hosting.

(Storage is plugged into the main game engine via the StorageManager interface; there are sub-packages for an MySQL-backed storage system, a BoltDB-backed one, and a simple in-memory one.)

In terms of replacing Firebase for the static file hosting, that should be quite simple, and just require a bit of configuration changes. server/README.md contains information towards the bottom about setting up either Firebase or Google Cloud Storage. Obviously, neither will work in China, but that should give you an idea of generally what kind of configuration you'd have to do on your own. (Note that in the demo environment you just run the simple static server, no Firebase Hosting required.)

It's theoretically possible to extract Firebase and supply a different authentication system. That would primarily require factoring out two pieces:

  1. server/static/index.html includes the firebase library and configs it. That would need to be replaced.
  2. server/static/src/boardgame-user.html is the component that actually interacts with the firebase library and upon success hits our own api endpoint to exchange for a server-side cookie for the boardgame library.
  3. The VerifyIDToken check in server/api/auth.go, which is where the JWT returned from the Firebase client-side library is checked for authenticity.

These changes wouldn't be particularly challenging to make. If you have another client-side authentication approach you'd like to use and concretely want to factor the project so it's easier to plug it in, pull requests are very welcome!

wadelee1986 commented 6 years ago

Thanks a lot,

I will try it out.

jkomoros commented 6 years ago

If you do plan to try a pull request to allow a different authentication server, a few notes on design:

For the 1st bullet, above, note that right now the server/static/index.html has a google analytics ID and Firebase config baked right into index.html. That's a bit odd because it makes customizing those config parameters a pain. Issue #231 captures the work to factor those out of index.html somehow.

For the 2nd bullet, we'd probably need some kind of approach similar to how we do game-src/ components, that is to say, a component at a specific import location with a specific API that encapsulates which authentication backend to use.

For the third bullet, I'd imagine we'd need an AuthenticationVerifier interface (similar in design and spirit to StorageManager) where a struct that implements that interfaces is passed at Server start up time.