Giter Club home page Giter Club logo

typegraphql-typeorm-auth's Introduction

Type-graphql + typeorm mail-only authentication stack

This repository holds a very basic implementation of (medium-like) authentication based on

Install

Install docker on your machine.

Run in your cli:

$ cd typegraphql-typeorm-auth

# downloads docker images and installs npm packages inside backend container
$ docker-compose build 

# run it
$ docker-compose up    

# optional:
# install packages locally to enable lint and package autocompletion in vs code
$ cd backend 
$ npm install   
           

visit localhost/api/playground

Prepare grapql playground

  • click on the settings icon top-right in playground and set "request.credentials": "same-origin",
  • otherwise session cookies are not sent to the api

Usage

Run the following sequence of graphql queries and mutations to test:

First, we make sure that we don't have access to creating a todo:

mutation{
    createTodo(text:"foo")
}

this should output: "message": "accessDenied". Next, we create an account or request login to an already existing account by:

mutation{
    requestSignIn(user:{email:"[email protected]"})
}

look at your consol. You should see an output like:

backend_1  | sign in using this token:
backend_1  | 55dd4e34-b3ca-4da2-8edc-db5064ad9079

in production, the printed token is sent to the user via email. Run the following for a test sign-in

mutation{
    signIn(token:"55dd4e34-b3ca-4da2-8edc-db5064ad9079")
}

The server replies with a cookie. You can test the login status with:

query{
  loggedinUser{email}
}

or simply create a todo again;

mutation{
    createTodo(text:"foo")
}

followed by listing all todos of the logged-in user:

query{
    todos{text}
}

Connecting a frontend

Check out react-yoga-mongo-nginx-docker to see how to connect a frontend container (with react) to the stack.

Testing

Resolvers can be tested using jest. You can see test implementations here:

  • src/resolvers/Session.test.ts
  • src/resolvers/Todo.test.js

You can run the tests with:

docker-compose run --rm backend npm test

All tests should pass without errors after a fresh clone of this repository.

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.