From e4b5bd6a673349cf5815cafadb7aa689fb5f8421 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 14 Sep 2023 11:24:19 +0800 Subject: [PATCH] Add code to join users without email on login --- .../App/Views/RootView/RootViewModel.swift | 2 - packages/api/src/routers/auth/apple_auth.ts | 12 +++++ packages/api/src/routers/auth/auth_router.ts | 45 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift index bc3121b7e..18f63fe1c 100644 --- a/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift @@ -17,8 +17,6 @@ public final class RootViewModel: ObservableObject { @Published public var showNewFeaturePrimer = false @AppStorage(UserDefaultKey.shouldShowNewFeaturePrimer.rawValue) var shouldShowNewFeaturePrimer = false - @Published var showMiniPlayer = false - public init() { registerFonts() diff --git a/packages/api/src/routers/auth/apple_auth.ts b/packages/api/src/routers/auth/apple_auth.ts index c852e9cfd..73cbf56a0 100644 --- a/packages/api/src/routers/auth/apple_auth.ts +++ b/packages/api/src/routers/auth/apple_auth.ts @@ -14,6 +14,7 @@ import { createWebAuthToken, suggestedUsername, } from './jwt_helpers' +import { analytics } from '../../utils/analytics' const appleBaseURL = 'https://appleid.apple.com' const audienceName = 'app.omnivore.app' @@ -145,6 +146,17 @@ export async function handleAppleWebAuth( ? ssoRedirectURL(ssoToken) : `${baseURL()}/home` + analytics.track({ + userId: user.id, + event: 'login', + properties: { + method: 'apple', + email: user.email, + username: user.profile.username, + env: env.server.apiEnv, + }, + }) + return { authToken, redirectURL, diff --git a/packages/api/src/routers/auth/auth_router.ts b/packages/api/src/routers/auth/auth_router.ts index 730b6bd7e..381d974f0 100644 --- a/packages/api/src/routers/auth/auth_router.ts +++ b/packages/api/src/routers/auth/auth_router.ts @@ -51,6 +51,7 @@ import { } from './google_auth' import { createWebAuthToken } from './jwt_helpers' import { createMobileAccountCreationResponse } from './mobile/account_creation' +import { analytics } from '../../utils/analytics' export interface SignupRequest { email: string @@ -323,6 +324,17 @@ export function authRouter() { ) } + analytics.track({ + userId: user.id, + event: 'login', + properties: { + method: 'google', + email: user.email, + username: user.profile.username, + env: env.server.apiEnv, + }, + }) + res.setHeader('set-cookie', result.headers['set-cookie']) await handleSuccessfulLogin(req, res, user, data.googleLogin.newUser) @@ -447,6 +459,17 @@ export function authRouter() { ) } + analytics.track({ + userId: user.id, + event: 'login', + properties: { + method: 'email', + email: user.email, + username: user.profile.username, + env: env.server.apiEnv, + }, + }) + await handleSuccessfulLogin(req, res, user, false) } catch (e) { logger.info('email-login exception:', e) @@ -548,6 +571,17 @@ export function authRouter() { } } + analytics.track({ + userId: user.id, + event: 'login', + properties: { + method: 'email_verification', + email: user.email, + username: user.profile.username, + env: env.server.apiEnv, + }, + }) + res.set('Message', 'EMAIL_CONFIRMED') await handleSuccessfulLogin(req, res, user, false) } catch (e) { @@ -664,6 +698,17 @@ export function authRouter() { ) } + analytics.track({ + userId: user.id, + event: 'login', + properties: { + method: 'password_reset', + email: user.email, + username: user.profile.username, + env: env.server.apiEnv, + }, + }) + await handleSuccessfulLogin(req, res, user, false) } catch (e) { logger.info('reset-password exception:', e)