Skip to content

Commit

Permalink
[#101]feat: 소셜 로그인 (구글, 카카오)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arios67 committed Mar 31, 2022
1 parent 175f613 commit d814bba
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ars/src/apis/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AuthController {
@Req() req: Request & IOAuthUser, //
@Res() res: Response,
) {
this.authService.loginOAuth(req, res);
await this.authService.loginOAuth(req, res);
}

@Get('/login/kakao')
Expand All @@ -27,6 +27,6 @@ export class AuthController {
@Req() req: Request & IOAuthUser, //
@Res() res: Response,
) {
this.authService.loginOAuth(req, res);
await this.authService.loginOAuth(req, res);
}
}
8 changes: 5 additions & 3 deletions ars/src/apis/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ export class AuthService {
const hashedPassword = await bcrypt.hash(String(password), 1);
const createUser = { ...rest, password: hashedPassword };
user = await this.userService.create({ ...createUser });
this.setRefreshToken({ user, res });
res.redirect('http://localhost:3000/socialLogin');
} else {
this.setRefreshToken({ user, res });
res.redirect('http://localhost:3000');
}

this.setRefreshToken({ user, res });
res.redirect('http://localhost:5500/frontend/login/index.html');
}
}
19 changes: 19 additions & 0 deletions ars/src/apis/user/dto/updateSocialUserInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Field, InputType } from '@nestjs/graphql';

@InputType()
export class UpdateSocialUser {
@Field(() => String)
email: string;

@Field(() => String)
nickname: string;

@Field(() => String)
phoneNum: string;

@Field(() => Boolean)
is_artist: boolean;

@Field(() => String, { nullable: true })
college?: string;
}
10 changes: 10 additions & 0 deletions ars/src/apis/user/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as bcrypt from 'bcrypt';
import { UseGuards } from '@nestjs/common';
import { GqlAuthAccessGuard } from 'src/common/auth/gql-auth.guard';
import { CurrentUser, ICurrentUser } from 'src/common/auth/gql-user.param';
import { UpdateSocialUser } from './dto/updateSocialUserInput';

@Resolver()
export class UserResolver {
Expand Down Expand Up @@ -33,6 +34,15 @@ export class UserResolver {
return await this.userService.create({ hashedPassword, ...rest });
}

@Mutation(() => User)
async updateSocialUser(
@Args('updateSocialUser') updateSocialUser: UpdateSocialUser,
) {
return await this.userService.updateSocialUser({
...updateSocialUser,
});
}

@Mutation(() => String)
async sendPhoneToken(@Args('phoneNum') phoneNum: string) {
if (phoneNum.length !== 10 && phoneNum.length !== 11) {
Expand Down
8 changes: 8 additions & 0 deletions ars/src/apis/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ export class UserService {
}
}

async updateSocialUser({ email, ...rest }) {
const user = await this.userRepository.findOne({ email });
return await this.userRepository.save({
...user,
...rest,
});
}

async sendTokenTOSMS(phoneNum, token) {
try {
const appKey = process.env.SMS_APP_KEY;
Expand Down
9 changes: 9 additions & 0 deletions ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type Mutation {
deleteComment(commentId: String!): Boolean!
createProfile(createProfileInput: CreateProfileInput!): Profile!
createUser(createUserInput: CreateUserInput!): User!
updateSocialUser(updateSocialUser: UpdateSocialUser!): User!
sendPhoneToken(phoneNum: String!): String!
phoneAuth(phoneNum: String!, token: String!): Boolean!
checkNickname(nickname: String!): Boolean!
Expand Down Expand Up @@ -225,3 +226,11 @@ input CreateUserInput {
is_artist: Boolean!
college: String
}

input UpdateSocialUser {
email: String!
nickname: String!
phoneNum: String!
is_artist: Boolean!
college: String
}
14 changes: 8 additions & 6 deletions frontend/login/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@
<img class="SocialLoginButtonImg" src="../img/google.png" />
<a
class="SocialLoginButtonTitle"
href="http://localhost:3000/login/google"
href="http://localhost:3000/login/google/callback"
>구글로 로그인</a
>
</div>
<div id="SocialLoginNaver">
<img class="SocialLoginButtonImg" src="../img/naver.png" />
<a
<a
class="SocialLoginButtonTitle"
href="http://localhost:3000/login/naver"
>네이버로 로그인</a>
href="http://daseul.shop/login/naver"
>네이버로 로그인</a
>
</div>
<div id="SocialLoginKakao">
<img class="SocialLoginButtonImg" src="../img/kakao.png" />
<a
<a
class="SocialLoginButtonTitle"
href="http://localhost:3000/login/kakao"
>카카오톡으로 로그인</a>
>카카오톡으로 로그인</a
>
</div>
<div id="SocialLoginFacebook">
<img class="SocialLoginButtonImg" src="../img/facebook.png" />
Expand Down

0 comments on commit d814bba

Please sign in to comment.