GithubHelp home page GithubHelp logo

vic / verily Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 2.0 71 KB

Demo application for APW subscriptions via websockets

Home Page: https://github.com/vic/apollo-phoenix-websocket

Elixir 61.18% JavaScript 38.82%
apollo-phoenix-websocket absinthe-graphql

verily's Introduction

Verily

This is a demo application to serve as an example of how to use Apollo Phoenix Websocket with Absinthe subscriptions.

Verily implements a mail authentication app, akin to Facebook AccountKit. That is, the user enters their email and clicks on Login, then the application awaits (via gql subscription) for the user to verify via a link on their inbox. The app receives the subscription data and logins the user automatically.

Installation

$ git clone https://github.com/vic/verily.git
$ cd verily
$ mix deps.get
$ yarn install
$ mix phoenix.server
$ open http://localhost:4000/

Code

The backend code is just a simple plug application that exposes a tiny GQL API with Absinthe.

Of these the most interesting one is the viewer subscription. It takes a device_token as topic (in my example, every client, eg mobile device or browser must generate a unique device token for its viewer subscription to work)

Verification is made via an email_login mutation that basically generates a random verification token (that will be sent via email) and starts a tiny process using an Elixir Registry. These veirfier processes live just five minutes, so that if no one confirms the email, the process automatically dies and the token becomes invalid. When the user cliks on the link with the token, the backend terminates the verifier process and sends the original email to the client via the GraphQL websocket subscription.

The client code is at web/static/js and most of it has nothing to do with Apollo Phoenix Websocket, haha, the apollo client configuration is made at apollo.js which also prefers to convert promises and observers into xstreams (as I just wanted to use them for this example) the api is defined at api.js, the app.js is where views and logic is bound together.

verily's People

Contributors

timbuckley avatar vic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.