-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f0d707
commit 92a8d1d
Showing
41 changed files
with
11,611 additions
and
891 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<button onclick="startKakao()">Kakao Login</button> | ||
<script src="./index.js"></script> | ||
<script | ||
src="https://t1.kakaocdn.net/kakao_js_sdk/2.3.0/kakao.min.js" | ||
integrity="sha384-70k0rrouSYPWJt7q9rSTKpiTfX6USlMYjZUtr1Du+9o4cGvhPAWxngdtVZDdErlh" | ||
crossorigin="anonymous" | ||
></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
async function startKakao() { | ||
try { | ||
const response = await fetch(`./api/auth/kakaokey`, { | ||
method: 'POST', | ||
}); | ||
const result = await response.json(); | ||
console.log(result.kakaoJSKey); | ||
console.log(result.kakaoRedirectURI); | ||
await Kakao.init(result.kakaoJSKey); | ||
await Kakao.Auth.authorize({ | ||
redirectUri: result.kakaoRedirectURI, | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
// alert( | ||
// '로그인이 정상적으로 완료되지 않았습니다. 새로고침 이후 다시 시도해 주세요.', | ||
// ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { KakaoStrategy } from './strategies'; | ||
import { AuthController } from './controllers'; | ||
import { AuthService, UserService } from './services'; | ||
import { | ||
AccessTokenRepository, | ||
RefreshTokenRepository, | ||
UserRepository, | ||
} from './repositories'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { | ||
AccessLog, | ||
AccessToken, | ||
RefreshToken, | ||
TokenBlacklist, | ||
User, | ||
} from './entities'; | ||
import { JwtModule, JwtService } from '@nestjs/jwt'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
@Module({ | ||
imports: [ | ||
JwtModule.register({ secret: process.env.JWT_SECRET }), | ||
TypeOrmModule.forFeature([ | ||
User, | ||
AccessToken, | ||
RefreshToken, | ||
AccessLog, | ||
TokenBlacklist, | ||
]), | ||
], | ||
controllers: [AuthController], | ||
providers: [ | ||
UserRepository, | ||
AccessTokenRepository, | ||
RefreshTokenRepository, | ||
|
||
KakaoStrategy, | ||
UserService, | ||
AuthService, | ||
], | ||
exports: [ | ||
UserRepository, | ||
AccessTokenRepository, | ||
RefreshTokenRepository, | ||
|
||
KakaoStrategy, | ||
UserService, | ||
AuthService, | ||
], | ||
}) | ||
export class AuthModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Controller, Get, Post, Req, UseGuards } from '@nestjs/common'; | ||
import { AuthService } from '../services'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
|
||
@Controller('api/auth') | ||
export class AuthController { | ||
constructor(private readonly authService: AuthService) {} | ||
|
||
@Get('login/kakao') | ||
@UseGuards(AuthGuard('kakao')) | ||
async kakaoCallback(@Req() req) { | ||
await this.authService.OAuthLogin(req); | ||
} | ||
@Post('kakaokey') | ||
async kakaoKey() { | ||
return await this.authService.kakaoKey(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './auth.controller'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class CreateUsserDto {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './create-user.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Column, Entity, ManyToOne } from 'typeorm'; | ||
import { BaseEntity } from 'src/common/enitty'; | ||
import { User } from './user.entity'; | ||
|
||
@Entity() | ||
export class AccessLog extends BaseEntity { | ||
@Column({ type: 'varchar', length: 512, nullable: true }) | ||
ua: string; | ||
|
||
@Column() | ||
endpoint: string; | ||
|
||
@Column() | ||
ip: string; | ||
|
||
@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' }) | ||
accessedAt: Date; | ||
|
||
@ManyToOne(() => User, user => user.accessLogs, { | ||
nullable: true, | ||
onDelete: 'CASCADE', | ||
}) | ||
user: User[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Column, Entity, ManyToOne } from 'typeorm'; | ||
import { User } from './user.entity'; | ||
import { BaseEntity } from 'src/common/enitty'; | ||
|
||
@Entity() | ||
export class AccessToken extends BaseEntity { | ||
@ManyToOne(() => User, user => user.accessToken) | ||
user: User; | ||
|
||
@Column({ type: 'varchar' }) | ||
token: string; | ||
|
||
@Column({ type: 'timestamp' }) | ||
expiresAt: Date; | ||
|
||
@Column({ default: false }) | ||
isRevoked: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './access-log.entity'; | ||
export * from './access-token.entity'; | ||
export * from './refresh-token.entity'; | ||
export * from './token-blacklist.entity'; | ||
export * from './user.entity'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Column, Entity, ManyToOne, PrimaryColumn } from 'typeorm'; | ||
import { User } from './user.entity'; | ||
import { BaseEntity } from 'src/common/enitty'; | ||
|
||
@Entity() | ||
export class RefreshToken extends BaseEntity { | ||
@ManyToOne(() => User, user => user.refreshToken) | ||
user: User; | ||
|
||
@PrimaryColumn() | ||
token: string; | ||
|
||
@Column({ type: 'timestamp' }) | ||
expiresAt: Date; | ||
|
||
@Column({ default: false }) | ||
isRevoked: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Column, Entity, PrimaryColumn } from 'typeorm'; | ||
import { BaseEntity } from 'src/common/enitty'; | ||
|
||
@Entity() | ||
export class TokenBlacklist extends BaseEntity { | ||
@PrimaryColumn() | ||
token: string; | ||
|
||
@Column() | ||
tokenType: 'access' | 'refresh'; | ||
|
||
@Column({ type: 'timestamp' }) | ||
expiresAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { BaseEntity } from 'src/common/enitty'; | ||
import { Column, Entity, OneToMany } from 'typeorm'; | ||
import { UserRole } from '../types'; | ||
import { AccessToken } from './access-token.entity'; | ||
import { RefreshToken } from './refresh-token.entity'; | ||
import { AccessLog } from './access-log.entity'; | ||
|
||
@Entity() | ||
export class User extends BaseEntity { | ||
@Column({ type: 'varchar' }) | ||
name: string; | ||
|
||
@Column({ type: 'varchar' }) | ||
password: string; | ||
|
||
@Column({ type: 'varchar', length: 50, nullable: true }) | ||
phone: string; | ||
|
||
@Column({ type: 'varchar', length: 30, default: 'user' }) | ||
role: UserRole; | ||
|
||
@OneToMany(() => AccessToken, token => token.user) | ||
accessToken: AccessToken[]; | ||
|
||
@OneToMany(() => RefreshToken, token => token.user) | ||
refreshToken: RefreshToken[]; | ||
|
||
@OneToMany(() => AccessLog, log => log.user) | ||
accessLogs: AccessLog[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './kakaoauth.guard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
|
||
@Injectable() | ||
export class KakaoAuthGuard extends AuthGuard('kakao') {} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.