From d3ca0698c63ee04a21bec3a4bcb7504d254db3cd Mon Sep 17 00:00:00 2001 From: musordmt Date: Tue, 16 Jul 2024 16:06:18 +0300 Subject: [PATCH] update get start url --- pkg/auth/components/login-panel.tsx | 18 ++++++++++++++++-- pkg/auth/components/signup-panel.tsx | 18 ++++++++++++++++-- pkg/auth/package.json | 2 +- pkg/auth/server/firebase-support.ts | 4 ++-- pkg/auth/service/impl/firebase-support.ts | 2 +- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/pkg/auth/components/login-panel.tsx b/pkg/auth/components/login-panel.tsx index 7be2e0a2..3880e76e 100644 --- a/pkg/auth/components/login-panel.tsx +++ b/pkg/auth/components/login-panel.tsx @@ -1,5 +1,5 @@ 'use client' -import { useState, type PropsWithChildren } from 'react' +import { useState, useEffect, type PropsWithChildren } from 'react' import { useRouter } from 'next/navigation' import { observer } from 'mobx-react-lite' import Link from 'next/link' @@ -62,6 +62,7 @@ const LoginPanel: React.FC { @@ -141,6 +142,19 @@ const LoginPanel: React.FC { + const emailPrefix = email.split('@')[0]; // Get the part before the @ symbol + const randomSuffix = Math.random().toString(36).substring(2, 8); // Generate a random string + return `${emailPrefix}_${randomSuffix}`; +} + + useEffect(() => { + if (auth.loggedIn) { + const username = auth.user?.email + if (username) setGetStartUrl('https://' + generateUsernameFromEmail(username) + '.' + getStartedUrl) + } + }, [auth]) + return ( {auth.loggedIn && !redirectUrl ? ( @@ -149,7 +163,7 @@ const LoginPanel: React.FC {/* this means the hanzo user isn't loaded yet ...*/}

You are signed in as {auth.user?.displayName ?? auth.user?.email}

- {getStartedUrl && } +
)} diff --git a/pkg/auth/components/signup-panel.tsx b/pkg/auth/components/signup-panel.tsx index 92138b59..230c747e 100644 --- a/pkg/auth/components/signup-panel.tsx +++ b/pkg/auth/components/signup-panel.tsx @@ -1,5 +1,5 @@ 'use client' -import { useState, type PropsWithChildren } from 'react' +import { useState, useEffect, type PropsWithChildren } from 'react' import { useRouter } from 'next/navigation' import { observer } from 'mobx-react-lite' import Link from 'next/link' @@ -62,6 +62,7 @@ const SignupPanel: React.FC { @@ -142,6 +143,19 @@ const SignupPanel: React.FC { + const emailPrefix = email.split('@')[0]; // Get the part before the @ symbol + const randomSuffix = Math.random().toString(36).substring(2, 8); // Generate a random string + return `${emailPrefix}_${randomSuffix}`; +} + + useEffect(() => { + if (auth.loggedIn) { + const username = auth.user?.email + if (username) setGetStartUrl('https://' + generateUsernameFromEmail(username) + '.' + getStartedUrl) + } + }, [auth]) + return ( {auth.loggedIn && !redirectUrl ? ( @@ -150,7 +164,7 @@ const SignupPanel: React.FC {/* this means the hanzo user isn't loaded yet ...*/}

You are signed in as {auth.user?.displayName ?? auth.user?.email}

- {getStartedUrl && } +
)} diff --git a/pkg/auth/package.json b/pkg/auth/package.json index 9481d541..a7ada9b3 100644 --- a/pkg/auth/package.json +++ b/pkg/auth/package.json @@ -1,6 +1,6 @@ { "name": "@hanzo/auth", - "version": "2.4.17", + "version": "2.4.18", "description": "Library with Firebase authentication.", "publishConfig": { "registry": "https://registry.npmjs.org/", diff --git a/pkg/auth/server/firebase-support.ts b/pkg/auth/server/firebase-support.ts index b4bfeecb..c60ee44c 100644 --- a/pkg/auth/server/firebase-support.ts +++ b/pkg/auth/server/firebase-support.ts @@ -24,10 +24,10 @@ const firebaseApp = 'firebase-admin-app' ) -const USER_INFO_COLLECTION = 'HZ_USER_INFO' +const USER_INFO_COLLECTION = 'USER_INFO' const auth = getAuth(firebaseApp) -const db = getFirestore(firebaseApp, 'lux-accounts') +const db = getFirestore(firebaseApp, 'accounts') async function isUserAuthenticated(session: string | undefined = undefined) { const _session = session ?? (await getSession()) diff --git a/pkg/auth/service/impl/firebase-support.ts b/pkg/auth/service/impl/firebase-support.ts index 78f86c56..8357b835 100644 --- a/pkg/auth/service/impl/firebase-support.ts +++ b/pkg/auth/service/impl/firebase-support.ts @@ -28,7 +28,7 @@ export const firebaseConfig = { const firebaseApp = getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0] export const auth = getAuth(firebaseApp) // :aa TODO should be in module conf in host app -export const db = getFirestore(firebaseApp, 'lux-accounts') +export const db = getFirestore(firebaseApp, 'accounts') export async function loginWithProvider(provider: string): Promise<{ success: boolean, user: User | null }> { const authProvider = (() => {