Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

added link / unlink google account functions

Blue Mouse7abba94f613e
diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts
index e1a3a93ea..77528b513 100644
--- a/src/auth/auth.service.ts
+++ b/src/auth/auth.service.ts
@@ -425,7 +425,11 @@ export class AuthService {
return this.userService.findUserByApiKey(apiKey)
}
- // Google SSO
+ /*
+ --------------------------------
+ Google SSO section
+ --------------------------------
+ */
async handleExistingUserGoogle(
user: User,
headers: unknown,
@@ -501,4 +505,30 @@ export class AuthService {
throw new InternalServerErrorException('Something went wrong while authenticating user with Google')
}
}
+
+ async linkGoogleAccount(userId: string, token: string) {
+ const tokenInfo = await this.oauth2Client.getTokenInfo(token)
+
+ const { sub } = tokenInfo
+
+ if (!sub) {
+ throw new UnauthorizedException()
+ }
+
+ const user = await this.userService.findUserById(userId)
+
+ if (!user) {
+ throw new UnauthorizedException()
+ }
+
+ await this.userService.updateUser(userId, {
+ googleId: sub,
+ })
+ }
+
+ async unlinkGoogleAccount(userId: string) {
+ await this.userService.updateUser(userId, {
+ googleId: null,
+ })
+ }
}