Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
remove authorizationCode
Browse files Browse the repository at this point in the history
  • Loading branch information
dyoshikawa committed Jan 18, 2022
1 parent 980714c commit fa7f823
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const buildDebugRegisterUserFastifyHandler =
channelId: body.channelId,
accessToken: body.accessToken,
idToken: body.idToken,
authorizationCode: '',
})

reply.type('application/json').code(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ export const buildLoginFastifyHandler =
userId: string
state: string
}
const authorizationCode = await loginUseCase(body.userId)
if (authorizationCode instanceof UserNotFoundError) {
const user = await loginUseCase(body.userId)
if (user instanceof UserNotFoundError) {
reply.redirect(302, '/niseline/authorize')
return
}

const url = new URL(clientEndpoint)
url.search = new URLSearchParams({
code: authorizationCode,
state: body.state,
userId: user.id,
}).toString()
reply.redirect(302, url.toString())
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,6 @@ export class UserLowRepository implements UserRepository {
return userRecord
}

async findByAuthorizationCode(
authorizationCode: string
): Promise<User | undefined> {
await this.low.read()
const userRecord: UserRecord | undefined = this.low.data?.find(
(r) => r.authorizationCode === authorizationCode
)
if (userRecord == null) {
return undefined
}

return userRecord
}

async save(user: User): Promise<void> {
await this.low.read()
this.low.data = this.low.data!.concat(user)
Expand Down
1 change: 0 additions & 1 deletion packages/server/src/component/user/domain/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export interface User {
channelId: string
idToken: string
accessToken: string
authorizationCode: string
}
1 change: 0 additions & 1 deletion packages/server/src/component/user/domain/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ export interface UserRepository {
find(id: string): Promise<User | undefined>
findByAccessToken(accessToken: string): Promise<User | undefined>
findByIdToken(idToken: string): Promise<User | undefined>
findByAuthorizationCode(authorizationCode: string): Promise<User | undefined>
save(user: User): Promise<void>
}

This file was deleted.

13 changes: 4 additions & 9 deletions packages/server/src/component/user/use-case/login-use-case.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { GenerateUuid } from '../../../util/uuid'
import { User } from '../domain/entity'
import { UserRepository } from '../domain/repository'

type AuthorizationCode = string

export class UserNotFoundError extends Error {}

export type LoginUseCase = (
userId: string
) => Promise<AuthorizationCode | UserNotFoundError>
export type LoginUseCase = (userId: string) => Promise<User | UserNotFoundError>

export const buildLoginUseCase =
({
userRepository,
generateUuid,
}: {
userRepository: UserRepository
generateUuid: GenerateUuid
Expand All @@ -23,7 +19,6 @@ export const buildLoginUseCase =
return new UserNotFoundError()
}

const uuid = generateUuid()
await userRepository.save({ ...user, authorizationCode: uuid })
return uuid
await userRepository.save({ ...user })
return user
}
18 changes: 0 additions & 18 deletions packages/server/src/di/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ import { buildShowUserComponentHandler } from '../component/user/adapter/handler
import { buildFriendshipStatusFastifyHandler } from '../component/user/adapter/handler/get-friendship-status-fastify-handler'
import { buildGetUserProfileFastifyHandler } from '../component/user/adapter/handler/get-user-profile-fastify-handler'
import { buildLoginFastifyHandler } from '../component/user/adapter/handler/login-fastify-handler'
import { buildTokenFastifyHandler } from '../component/user/adapter/handler/token-fastify-handler'
import { buildVerifyAccessTokenFastifyHandler } from '../component/user/adapter/handler/verify-access-token-fastify-handler'
import { buildVerifyIdTokenFastifyHandler } from '../component/user/adapter/handler/verify-id-token-fastify-handler'
import { UserLowRepository } from '../component/user/adapter/repository/user-repository'
import { buildFindUserByAccessTokenUseCase } from '../component/user/use-case/find-user-by-access-token-use-case'
import { buildFindUserByAuthorizationCodeUseCase } from '../component/user/use-case/find-user-by-authorization-code-use-case'
import { buildFindUserByIdTokenUseCase } from '../component/user/use-case/find-user-by-id-token-use-case'
import { buildFindUserUseCase } from '../component/user/use-case/find-user-use-case'
import { buildLoginUseCase } from '../component/user/use-case/login-use-case'
Expand Down Expand Up @@ -112,13 +110,6 @@ export const bootstrap = (): Container => {
generateUuid: c.get(DI_TYPE.GENERATE_UUID),
})
)
container
.bind(DI_TYPE.FIND_USER_BY_AUTHORIZATION_CODE_USE_CASE)
.toDynamicValue(({ container: c }) =>
buildFindUserByAuthorizationCodeUseCase({
userRepository: c.get(DI_TYPE.USER_COMPONENT_USER_REPOSITORY),
})
)
container
.bind(DI_TYPE.FIND_USER_BY_ACCESS_TOKEN_USE_CASE)
.toDynamicValue(({ container: c }) =>
Expand Down Expand Up @@ -181,15 +172,6 @@ export const bootstrap = (): Container => {
loginUseCase: c.get(DI_TYPE.LOGIN_USE_CASE),
})
)
container
.bind(DI_TYPE.TOKEN_FASTIFY_HANDLER)
.toDynamicValue(({ container: c }) =>
buildTokenFastifyHandler({
findUserByAuthorizationTokenUseCase: c.get(
DI_TYPE.FIND_USER_BY_AUTHORIZATION_CODE_USE_CASE
),
})
)
container
.bind(DI_TYPE.FIND_USER_BY_ACCESS_TOKEN_FASTIFY_HANDLER)
.toDynamicValue(({ container: c }) =>
Expand Down
4 changes: 0 additions & 4 deletions packages/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ fastify.post(
'/niseline/login',
container.get<RouteHandlerMethod>(DI_TYPE.LOGIN_FASTIFY_HANDLER)
)
fastify.post(
'/niseline/token',
container.get<RouteHandlerMethod>(DI_TYPE.TOKEN_FASTIFY_HANDLER)
)

/**
* Login API
Expand Down
1 change: 0 additions & 1 deletion packages/server/src/util/db/lowdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const initLowDb = () => {
channelId: 'DEFAULT_CHANNEL',
accessToken: 'DEFAULT_USER_ACCESS_TOKEN',
idToken: 'DEFAULT_USER_ID_TOKEN',
authorizationCode: '',
},
]
fs.writeFileSync('./tmp/users.json', JSON.stringify(userJson, null, 2))
Expand Down

0 comments on commit fa7f823

Please sign in to comment.