MCPcopy Create free account
hub / github.com/CodeFox-Repo/codefox / handleGoogleCallback

Method handleGoogleCallback

backend/src/auth/auth.service.ts:543–617  ·  view source on GitHub ↗

* Handles the Google OAuth callback: find or create the user, then issue JWT(s). * @param googleProfile The user object attached by the GoogleStrategy validate() method. * @returns an object containing accessToken & refreshToken (if you use refresh tokens).

(googleProfile: {
    googleId: string;
    email: string;
    firstName?: string;
    lastName?: string;
  })

Source from the content-addressed store, hash-verified

541 where: { id: roleId },
542 relations: ['menus'],
543 });
544 } catch (error) {
545 Logger.error(`Failed to assign menus to role: ${error.message}`);
546 throw error;
547 }
548 }
549
550 async removeMenuFromRole(roleId: string, menuId: string): Promise<Role> {
551 const role = await this.roleRepository.findOne({
552 where: { id: roleId },
553 relations: ['menus'],
554 });
555
556 if (!role) {
557 throw new NotFoundException(`Role with ID "${roleId}" not found`);
558 }
559
560 const menuIndex = role.menus?.findIndex((menu) => menu.id === menuId);
561
562 if (menuIndex === -1) {
563 throw new NotFoundException(
564 `Menu with ID "${menuId}" not found in role "${role.name}"`,
565 );
566 }
567
568 role.menus.splice(menuIndex, 1);
569
570 try {
571 await this.roleRepository.save(role);
572 Logger.log(`Menu removed from role ${role.name} successfully`);
573
574 return await this.roleRepository.findOne({
575 where: { id: roleId },
576 relations: ['menus'],
577 });
578 } catch (error) {
579 Logger.error(`Failed to remove menu from role: ${error.message}`);
580 throw error;
581 }
582 }
583
584 async assignRoles(userId: string, roleIds: string[]): Promise<User> {
585 const user = await this.userRepository.findOne({
586 where: { id: userId },
587 relations: ['roles'],
588 });
589
590 if (!user) {
591 throw new NotFoundException(`User with ID "${userId}" not found`);
592 }
593
594 const roles = await this.roleRepository.findBy({ id: In(roleIds) });
595
596 if (roles.length !== roleIds.length) {
597 throw new NotFoundException('Some roles were not found');
598 }
599
600 if (!user.roles) {

Callers 1

googleAuthCallbackMethod · 0.80

Calls 2

createRefreshTokenMethod · 0.95
storeAccessTokenMethod · 0.80

Tested by

no test coverage detected