Skip to content

Commit

Permalink
[#114]feat: 소셜 로그인 유저 정보 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Arios67 committed Apr 1, 2022
1 parent 6eae714 commit a848054
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 7 additions & 2 deletions ars/src/apis/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ export class AuthService {
}

async loginOAuth(req, res) {
let user = await this.userService.findOne({ email: req.user.email });

let email = req.user.email;
console.log(email + '****************!!');
let user = await this.userService.findOne(email);
console.log('LLLLLLOOOOOO !' + user);
if (!user) {
const { password, ...rest } = req.user;
const hashedPassword = await bcrypt.hash(String(password), 1);
const createUser = { ...rest, password: hashedPassword };
user = await this.userService.create({ ...createUser });
this.setRefreshToken({ user, res });
console.log('user created !!!');
res.redirect('https://artipul.shop/socialLogin');
return user;
} else {
this.setRefreshToken({ user, res });
res.redirect('https://artipul.shop/');
res.send(user);
return user;
}
}
}
12 changes: 8 additions & 4 deletions ars/src/apis/user/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { User } from './entities/user.entity';
import { UserService } from './user.service';
import * as bcrypt from 'bcrypt';
import { UseGuards } from '@nestjs/common';
import { GqlAuthAccessGuard } from 'src/common/auth/gql-auth.guard';
import {
GqlAuthAccessGuard,
GqlAuthRefreshGuard,
} from 'src/common/auth/gql-auth.guard';
import { CurrentUser, ICurrentUser } from 'src/common/auth/gql-user.param';
import { UpdateSocialUser } from './dto/updateSocialUserInput';

Expand All @@ -23,9 +26,10 @@ export class UserResolver {
return await this.userService.findUserEmail({ phoneNum });
}

@Query(() => String)
async findSocialUser(@Args('email') email: string) {
const user = await this.userService.findOne(email);
@UseGuards(GqlAuthRefreshGuard)
@Query(() => User)
async findSocialUser(@CurrentUser() currentUser: ICurrentUser) {
return await this.userService.findOne(currentUser.email);
}

@Mutation(() => User)
Expand Down
2 changes: 1 addition & 1 deletion ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type Query {
fetchArtistProfile(artId: String!): Profile!
fetchUser: User!
findUserEmail(phoneNum: String!): String!
findSocialUser(email: String!): String!
findSocialUser: User!
fetchPointTransactions: [PointTransaction!]!
}

Expand Down

0 comments on commit a848054

Please sign in to comment.