Skip to content

(WIP) 認証機能のマイクロサービス化 #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 62 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
cd8bd82
Add @auth0/nextjs-auth0 and update nextjs
suzukalight Nov 2, 2020
c138b97
Add .env.default to use auth0
suzukalight Nov 2, 2020
ffe19f3
Add api routes to handle auth0 connection
suzukalight Nov 2, 2020
1c77558
Add auth0 util
suzukalight Nov 2, 2020
a1f7825
Move old login component
suzukalight Nov 2, 2020
81ca55a
Update index page
suzukalight Nov 2, 2020
2a35b48
Add AuthAuth0Entity
suzukalight Nov 2, 2020
f4032af
Remove email from UserEntity
suzukalight Nov 2, 2020
cc45236
Update tests for UserEntity
suzukalight Nov 2, 2020
0b1b49b
Add interfaces for SignInAuth0 and SignUpAuth0 usecase
suzukalight Nov 2, 2020
c493b64
Add SignInAuth0 and SignUpAuth0 usecase
suzukalight Nov 2, 2020
8dc0fff
Add mocks for SignInAuth0 and SignUpAuth0 usecase
suzukalight Nov 2, 2020
20dfb66
Add tests of SignUpAuth0 usecase
suzukalight Nov 2, 2020
848ee6a
Add tests of SignInAuth0 usecase
suzukalight Nov 2, 2020
faef4b9
Update schema
suzukalight Nov 2, 2020
7d272c1
Fix
suzukalight Nov 2, 2020
a32e3a4
Remove email from User
suzukalight Nov 2, 2020
38f5790
Run db:migration:generate
suzukalight Nov 2, 2020
b5e104c
Add AuthAuth0 entity to typeorm
suzukalight Nov 2, 2020
7ec188f
Add AuthAuth0 repository to typeorm
suzukalight Nov 2, 2020
dd347d4
Add Auth0 presenters
suzukalight Nov 2, 2020
4ebd990
Add mutations for Auth0
suzukalight Nov 2, 2020
3c2ea58
Lint
suzukalight Nov 2, 2020
ff915ab
Fix to remove user.email
suzukalight Nov 2, 2020
2421999
Fix
suzukalight Nov 2, 2020
efd4a73
Remove email from User
suzukalight Nov 2, 2020
02e4380
Fix
suzukalight Nov 2, 2020
0a893cd
Merge signin and signup to signInOrSignUp usecase
suzukalight Nov 3, 2020
43b300d
Update schema
suzukalight Nov 3, 2020
eacab69
Fix
suzukalight Nov 3, 2020
eb129d4
Merge signin and signup mutation to signInOrSignUp
suzukalight Nov 3, 2020
cbe02b4
Fix schema
suzukalight Nov 3, 2020
ac4990e
Lint
suzukalight Nov 3, 2020
5ad89b9
Add orm entity definition of AuthAuth0
suzukalight Nov 8, 2020
8558bc5
Update login page
suzukalight Nov 9, 2020
13549c1
Add callback api
suzukalight Nov 9, 2020
fdb0451
Update redirection in index
suzukalight Nov 9, 2020
0b1c0e8
Update todos page
suzukalight Nov 9, 2020
95ed98a
Add backend-auth-local project
suzukalight Nov 10, 2020
92b0d1d
Move value objects to common project
suzukalight Nov 10, 2020
3736aca
Move AuthEmailPassword usecase to auth-local project
suzukalight Nov 10, 2020
b6f8763
Update import path
suzukalight Nov 10, 2020
e773d84
Add project config to common
suzukalight Nov 10, 2020
2d1fc46
Remove Auth from backend
suzukalight Nov 10, 2020
1c61e5b
Update tsconfig
suzukalight Nov 10, 2020
c239bb8
Rename to auth-local
suzukalight Nov 10, 2020
49a06fa
Fix
suzukalight Nov 10, 2020
6c61204
Add signIn and signUp mutation to auth-local
suzukalight Nov 10, 2020
7561988
Split auth schema
suzukalight Nov 10, 2020
1abf3d0
Use auth-local-schema
suzukalight Nov 10, 2020
1d4a41b
Split integration tests
suzukalight Nov 10, 2020
fd37abe
Add tests to Role
suzukalight Nov 10, 2020
5026d46
Fix tests
suzukalight Nov 10, 2020
358c3e6
Fix Role
suzukalight Nov 10, 2020
cacba2f
Fix .env.default
suzukalight Nov 15, 2020
9e7b914
Fix
suzukalight Nov 15, 2020
b0f29bc
Move schema to auth-local
suzukalight Nov 16, 2020
dfa1e1b
Update build scripts
suzukalight Nov 16, 2020
24a1a23
Update import paths
suzukalight Nov 16, 2020
8cc7082
Fix
suzukalight Nov 16, 2020
a870e85
Move schema
suzukalight Nov 17, 2020
b23bd77
Update import path
suzukalight Nov 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@
"dev": "run-p dev:*",
"dev:backend": "yarn workspace backend dev",
"dev:frontend": "yarn workspace frontend dev",
"build": "run-s build:common build:schema build:domain-model build:backend build:frontend",
"dev:auth-local": "yarn workspace auth-local dev",
"build": "run-s build:common build:schema build:domain-model build:backend build:frontend build:auth-local",
"build:common": "yarn workspace common build",
"build:schema": "yarn workspace schema build",
"build:domain-model": "yarn workspace domain-model build",
"build:backend": "yarn workspace backend build",
"build:frontend": "yarn workspace frontend build",
"rebuild": "run-s rebuild:common rebuild:schema rebuild:domain-model rebuild:backend rebuild:frontend",
"build:auth-local": "yarn workspace auth-local build",
"rebuild": "run-s rebuild:common rebuild:schema rebuild:domain-model rebuild:backend rebuild:frontend rebuild:auth-local",
"rebuild:common": "yarn workspace common rebuild",
"rebuild:schema": "yarn workspace schema rebuild",
"rebuild:domain-model": "yarn workspace domain-model rebuild",
"rebuild:backend": "yarn workspace backend rebuild",
"rebuild:frontend": "yarn workspace frontend rebuild",
"reset:backend": "run-s rebuild:common rebuild:schema rebuild:domain-model rebuild:backend",
"clean": "run-s clean:frontend clean:backend clean:schema clean:domain-model clean:common clean:modules",
"rebuild:auth-local": "yarn workspace auth-local rebuild",
"clean": "run-s clean:auth-local clean:frontend clean:backend clean:schema clean:domain-model clean:common clean:modules",
"clean:modules": "rimraf node_modules",
"clean:common": "yarn workspace common clean",
"clean:schema": "yarn workspace schema clean",
"clean:domain-model": "yarn workspace domain-model clean",
"clean:backend": "yarn workspace backend clean",
"clean:frontend": "yarn workspace frontend clean",
"clean:auth-local": "yarn workspace auth-local clean",
"start": "run-p start:*",
"start:backend": "yarn workspace backend start",
"start:frontend": "yarn workspace frontend start",
Expand All @@ -42,24 +45,32 @@
"lint": "eslint --fix ./src",
"format": "prettier --write -l \"./src/**/*.{js,ts,graphql}\"",
"test": "run-s test:*",
"test:common": "yarn workspace common test",
"test:domain": "yarn workspace domain-model test",
"test:backend": "yarn workspace backend test",
"test:auth-local": "yarn workspace auth-local test",
"codegen": "run-s codegen:schema codegen:frontend",
"codegen:schema": "yarn workspace schema codegen",
"codegen:frontend": "yarn workspace frontend codegen",
"codegen:auth-local": "yarn workspace auth-local codegen",
"docker:upd": "run-p docker:upd:*",
"docker:upd:backend": "yarn workspace backend docker:upd",
"docker:upd:auth-local": "yarn workspace auth-local docker:upd",
"docker:down": "run-p docker:down:*",
"docker:down:backend": "yarn workspace backend docker:down",
"docker:down:auth-local": "yarn workspace auth-local docker:down",
"db:migrate": "yarn workspace backend db:migrate",
"db:migration:generate": "yarn workspace backend db:migration:generate",
"db:seed": "yarn workspace backend db:seed",
"db:migration:generate:backend": "yarn workspace backend db:migration:generate",
"db:migration:generate:auth-local": "yarn workspace auth-local db:migration:generate",
"db:seed:backend": "yarn workspace backend db:seed",
"db:seed:auth-local": "yarn workspace auth-local db:seed",
"setup": "run-s rebuild setup:domain-model setup:backend",
"setup:domain-model": "yarn workspace domain-model setup",
"setup:backend": "yarn workspace backend setup",
"setup:env": "run-p setup:env:domain-model setup:env:backend",
"setup:env:domain-model": "yarn workspace domain-model setup:env",
"setup:env:backend": "yarn workspace backend setup:env"
"setup:env:backend": "yarn workspace backend setup:env",
"setup:env:auth-local": "yarn workspace auth-local setup:env"
},
"devDependencies": {
"@graphql-codegen/cli": "^1.17.7",
Expand Down
2 changes: 2 additions & 0 deletions src/auth-local/.env.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JWT_SECRET="YourSecretPhrase"
JWT_EXPIRES_IN="2d"
5 changes: 5 additions & 0 deletions src/auth-local/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build/
docker/db/data
.env
tsconfig.tsbuildinfo
test_db/
15 changes: 15 additions & 0 deletions src/auth-local/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
overwrite: true
schema: 'schema/**/*.graphql'
generates:
src/generated/resolver-types.ts:
plugins:
- typescript
- typescript-resolvers
config:
useIndexSignature: true
src/generated/schema.graphql:
plugins:
- schema-ast
config:
scalars:
DateTime: Date
24 changes: 24 additions & 0 deletions src/auth-local/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.1'

services:
# MySQL
db:
image: mysql:5.7
container_name: graphql_clean_dev_mysql_host_auth_local
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: graphql_clean_dev_auth_local
MYSQL_USER: docker
MYSQL_PASSWORD: docker
TZ: 'Asia/Tokyo'
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
volumes:
- mysql-data:/var/lib/mysql
- ./docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
- ./docker/db/sql:/docker-entrypoint-initdb.d
ports:
- 3306:3306

volumes:
mysql-data:
driver: local
6 changes: 6 additions & 0 deletions src/auth-local/docker/db/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci

[client]
default-character-set=utf8mb4
44 changes: 44 additions & 0 deletions src/auth-local/docker/wait-mysql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'reflect-metadata';
import { Connection, createConnection } from 'typeorm';

const sleep = async (ms: number) =>
new Promise((resolve) => {
setTimeout(() => {
resolve();
}, ms);
});

const createDbConnection = async () => {
return createConnection({
type: 'mysql',
host: '127.0.0.1',
port: 3306,
username: 'docker',
password: 'docker',
database: 'graphql_clean_dev_auth_local',
synchronize: false,
logging: false,
});
};

const waitConnection = async () => {
let count = 30;
let dbConnection: Connection | undefined;

while (count > 0) {
--count;
try {
dbConnection = await createDbConnection();
} catch (e) {
await sleep(1000);
continue;
}

if (dbConnection?.isConnected) break;
await sleep(1000);
}

process.exit();
};

waitConnection();
12 changes: 12 additions & 0 deletions src/auth-local/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
globals: {
'ts-jest': {
tsConfig: 'tsconfig.json',
},
},
testMatch: ['**/__tests__/*.+(ts|tsx|js)'],
};
16 changes: 16 additions & 0 deletions src/auth-local/ormconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "mysql",
"host": "127.0.0.1",
"port": 3306,
"username": "docker",
"password": "docker",
"database": "graphql_clean_dev_auth_local",
"synchronize": false,
"logging": false,
"entities": ["src/repository/typeorm/**/entity/*.ts"],
"migrations": ["src/infrastructure/typeorm/migration/**/*.ts"],
"subscribers": ["src/infrastructure/typeorm/subscriber/**/*.ts"],
"cli": {
"migrationsDir": "src/infrastructure/typeorm/migration"
}
}
66 changes: 66 additions & 0 deletions src/auth-local/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "auth-local",
"version": "1.0.0",
"main": "index.js",
"author": "suzukalight <[email protected]>",
"license": "MIT",
"scripts": {
"dev": "ts-node-dev ./src/index.ts",
"build": "tsc -b",
"rebuild": "run-s clean reinstall build",
"clean": "run-p clean:*",
"clean:build": "rimraf build",
"clean:modules": "rimraf node_modules",
"clean:test_db": "rimraf test_db",
"reinstall": "yarn install",
"start": "node build/index.js",
"test": "env-cmd -f .env.default jest",
"test:watch": "yarn test --watch",
"test:cov": "run-s test:cov:run test:cov:open",
"test:cov:run": "yarn test --coverage",
"test:cov:open": "npx http-server -o ./coverage/lcov-report",
"test:cov:watch": "yarn test --coverage --watch",
"docker:up": "docker-compose up",
"docker:upd": "docker-compose up -d",
"docker:down": "docker-compose down",
"docker:down:rmi": "docker-compose down --rmi all --volumes --remove-orphans",
"typeorm": "node --require ts-node/register ../../node_modules/typeorm/cli.js",
"db:migrate": "yarn typeorm migration:run",
"db:migrate:revert": "yarn typeorm migration:revert",
"db:migration:generate": "yarn typeorm migration:generate -n",
"db:seed": "ts-node ./src/infrastructure/typeorm/seeder/index.ts",
"setup": "run-s setup:env docker:upd setup:wait:mysql db:migrate db:seed",
"setup:env": "node -e \"require('fs').copyFileSync('./.env.default', './.env')\"",
"setup:wait:mysql": "node --require ts-node/register ./docker/wait-mysql.ts",
"codegen": "graphql-codegen --config codegen.yml"
},
"dependencies": {
"@graphql-tools/graphql-file-loader": "^6.0.16",
"@graphql-tools/load": "^6.0.16",
"@graphql-tools/schema": "^6.0.16",
"apollo-server": "^2.18.2",
"apollo-server-express": "^2.18.2",
"common": "file:../common",
"cors": "^2.8.5",
"date-fns": "^2.16.1",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"graphql": "^15.3.0",
"graphql-scalars": "^1.2.6",
"mysql2": "^2.1.0",
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.0.0",
"typeorm": "^0.2.25",
"uuid": "^8.3.1"
},
"devDependencies": {
"@types/bluebird": "^3.5.32",
"@types/graphql-resolvers": "^0.3.0",
"@types/node": "^14.0.27",
"@types/uuid": "^8.3.0",
"apollo-server-testing": "^2.18.2",
"ts-node": "^8.10.2",
"ts-node-dev": "^1.0.0-pre.56",
"typescript": "^3.9.7"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { PropertyRequiredError } from 'common';
import { PropertyRequiredError, denyIllegalEmail, denyIllegalPassword } from 'common';

import { denyIllegalEmail } from '../common/Email';
import { denyIllegalPassword } from '../common/Password';
import { TimeStampTypes, denyDoesNotHaveRequiredProperties } from '../utils';

export type AuthEmailPasswordDto = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Email, Password, ID } from 'common';

import { AuthEmailPasswordDto, denyIllegalAuthEmailPasswordDto } from './AuthEmailPasswordDto';
import { Email } from '../common/Email';
import { Password } from '../common/Password';
import { ID } from '../common/ID';

export class AuthEmailPasswordEntity {
private email: Email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { IllegalArgumentError, PropertyRequiredError } from 'common';
import { IllegalArgumentError, PropertyRequiredError, encryptPassword } from 'common';

import { AuthEmailPasswordDto } from '../AuthEmailPasswordDto';
import { AuthEmailPasswordEntity } from '../AuthEmailPasswordEntity';
import { encryptPassword } from '../../common/Password';

describe('AuthEmailPasswordEntity', () => {
const password = 'pass1234';
Expand Down
14 changes: 14 additions & 0 deletions src/auth-local/src/entity/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { PropertyRequiredError } from 'common';

export type TimeStampTypes = {
createdAt?: Date | null;
updatedAt?: Date | null;
deletedAt?: Date | null;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const denyDoesNotHaveRequiredProperties = (entity: any, properties: string[]) => {
properties.forEach((prop) => {
if (!(prop in entity)) throw new PropertyRequiredError(prop);
});
};
Loading