mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 18:01:09 +02:00
🧑💻 feat(dx): improve local development experience
- Add dev credentials pre-fill on login page (dev@manacore.local) - Add initialPassword prop to LoginPage component - Add seed script for dev user (pnpm db:seed:dev in mana-core-auth) - Add OLLAMA_URL to .env.development for Mac Mini connection
This commit is contained in:
parent
ca00672016
commit
e72f3b7865
5 changed files with 138 additions and 4 deletions
|
|
@ -71,6 +71,11 @@ DEV_USER_ID=00000000-0000-0000-0000-000000000000
|
|||
# Get your API key at https://openrouter.ai/keys
|
||||
OPENROUTER_API_KEY=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
|
||||
|
||||
# Ollama (local LLM server - runs on Mac Mini)
|
||||
# Use SSH tunnel: ssh -L 11434:localhost:11434 mana-server
|
||||
# Or set to direct URL if Ollama is exposed (e.g., https://ollama.mana.how)
|
||||
OLLAMA_URL=http://localhost:11434
|
||||
|
||||
# ============================================
|
||||
# MAERCHENZAUBER PROJECT
|
||||
# ============================================
|
||||
|
|
@ -160,6 +165,14 @@ NUTRIPHI_S3_PUBLIC_URL=http://localhost:9000/nutriphi-storage
|
|||
ZITARE_BACKEND_PORT=3007
|
||||
ZITARE_DATABASE_URL=postgresql://manacore:devpassword@localhost:5432/zitare
|
||||
|
||||
# ============================================
|
||||
# ZITARE TELEGRAM BOT
|
||||
# ============================================
|
||||
|
||||
ZITARE_BOT_PORT=3303
|
||||
ZITARE_BOT_DATABASE_URL=postgresql://manacore:devpassword@localhost:5432/zitare_bot
|
||||
ZITARE_BOT_TELEGRAM_TOKEN=
|
||||
|
||||
# ============================================
|
||||
# PRESI PROJECT
|
||||
# ============================================
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { locale } from 'svelte-i18n';
|
||||
import { browser } from '$app/environment';
|
||||
import { browser, dev } from '$app/environment';
|
||||
import { LoginPage } from '@manacore/shared-auth-ui';
|
||||
import { getLoginTranslations } from '@manacore/shared-i18n';
|
||||
import { ChatLogo } from '@manacore/shared-branding';
|
||||
|
|
@ -11,6 +11,10 @@
|
|||
import LanguageSelector from '$lib/components/LanguageSelector.svelte';
|
||||
import '$lib/i18n';
|
||||
|
||||
// Dev credentials - pre-filled in development mode
|
||||
const DEV_EMAIL = 'dev@manacore.local';
|
||||
const DEV_PASSWORD = 'devpassword123';
|
||||
|
||||
// Get redirect URL from query params or sessionStorage (set by AuthGateModal in guest mode)
|
||||
const redirectTo = $derived.by(() => {
|
||||
const queryRedirect = $page.url.searchParams.get('redirectTo');
|
||||
|
|
@ -34,7 +38,10 @@
|
|||
|
||||
// Read verification status from query params (set after email verification)
|
||||
const verified = $derived($page.url.searchParams.get('verified') === 'true');
|
||||
const initialEmail = $derived($page.url.searchParams.get('email') || '');
|
||||
|
||||
// In dev mode, pre-fill with dev credentials unless email is provided via query param
|
||||
const initialEmail = $derived($page.url.searchParams.get('email') || (dev ? DEV_EMAIL : ''));
|
||||
const initialPassword = $derived(dev ? DEV_PASSWORD : '');
|
||||
|
||||
async function handleSignIn(email: string, password: string) {
|
||||
return authStore.signIn(email, password);
|
||||
|
|
@ -61,6 +68,7 @@
|
|||
{translations}
|
||||
{verified}
|
||||
{initialEmail}
|
||||
{initialPassword}
|
||||
>
|
||||
{#snippet headerControls()}
|
||||
<LanguageSelector />
|
||||
|
|
|
|||
|
|
@ -80,6 +80,8 @@
|
|||
verified?: boolean;
|
||||
/** Pre-fill email field (e.g., after email verification) */
|
||||
initialEmail?: string;
|
||||
/** Pre-fill password field (for dev mode) */
|
||||
initialPassword?: string;
|
||||
}
|
||||
|
||||
let {
|
||||
|
|
@ -102,6 +104,7 @@
|
|||
translations = {},
|
||||
verified = false,
|
||||
initialEmail = '',
|
||||
initialPassword = '',
|
||||
}: Props = $props();
|
||||
|
||||
const t = $derived({ ...defaultTranslations, ...translations });
|
||||
|
|
@ -110,7 +113,7 @@
|
|||
let error = $state<string | null>(null);
|
||||
let errorField = $state<'email' | 'password' | 'general' | null>(null);
|
||||
let email = $state(initialEmail);
|
||||
let password = $state('');
|
||||
let password = $state(initialPassword);
|
||||
let showPassword = $state(false);
|
||||
let rememberMe = $state(false);
|
||||
let showSuccess = $state(false);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
"db:push": "drizzle-kit push",
|
||||
"db:generate": "drizzle-kit generate",
|
||||
"db:migrate": "tsx src/db/migrate.ts",
|
||||
"db:studio": "drizzle-kit studio"
|
||||
"db:studio": "drizzle-kit studio",
|
||||
"db:seed:dev": "tsx src/db/seed-dev-user.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@google/generative-ai": "^0.24.1",
|
||||
|
|
|
|||
109
services/mana-core-auth/src/db/seed-dev-user.ts
Normal file
109
services/mana-core-auth/src/db/seed-dev-user.ts
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* Seed Dev User Script
|
||||
*
|
||||
* Creates a development user for easy local testing.
|
||||
* Run with: pnpm db:seed:dev
|
||||
*
|
||||
* IMPORTANT: The auth server must be running for this script to work!
|
||||
* Start it first with: pnpm start:dev
|
||||
*
|
||||
* Credentials:
|
||||
* Email: dev@manacore.local
|
||||
* Password: devpassword123
|
||||
*/
|
||||
|
||||
import { config } from 'dotenv';
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import { users } from './schema/auth.schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
// Load environment variables
|
||||
config();
|
||||
|
||||
const DEV_USER = {
|
||||
email: 'dev@manacore.local',
|
||||
password: 'devpassword123',
|
||||
name: 'Dev User',
|
||||
};
|
||||
|
||||
const AUTH_URL = process.env.BASE_URL || 'http://localhost:3001';
|
||||
|
||||
async function seedDevUser() {
|
||||
const databaseUrl =
|
||||
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/manacore';
|
||||
|
||||
console.log('🌱 Seeding dev user...');
|
||||
console.log(` Email: ${DEV_USER.email}`);
|
||||
console.log(` Password: ${DEV_USER.password}`);
|
||||
console.log('');
|
||||
|
||||
const connection = postgres(databaseUrl, { max: 1 });
|
||||
const db = drizzle(connection);
|
||||
|
||||
try {
|
||||
// Check if user already exists
|
||||
const existingUsers = await db.select().from(users).where(eq(users.email, DEV_USER.email));
|
||||
|
||||
if (existingUsers.length > 0) {
|
||||
// User exists - just make sure email is verified
|
||||
await db.update(users).set({ emailVerified: true }).where(eq(users.email, DEV_USER.email));
|
||||
|
||||
console.log('✅ Dev user already exists, email verification ensured.');
|
||||
await connection.end();
|
||||
return;
|
||||
}
|
||||
|
||||
// Register user via HTTP API (auth server must be running)
|
||||
console.log(`📡 Registering user via API at ${AUTH_URL}...`);
|
||||
|
||||
const response = await fetch(`${AUTH_URL}/api/v1/auth/register`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
email: DEV_USER.email,
|
||||
password: DEV_USER.password,
|
||||
name: DEV_USER.name,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
throw new Error(`Registration failed: ${response.status} - ${error}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
console.log(` User created with ID: ${result.user?.id || 'unknown'}`);
|
||||
|
||||
// Set emailVerified to true (skip email verification for dev user)
|
||||
await db.update(users).set({ emailVerified: true }).where(eq(users.email, DEV_USER.email));
|
||||
|
||||
console.log('✅ Dev user created and email verified!');
|
||||
console.log('');
|
||||
console.log('You can now login with:');
|
||||
console.log(` Email: ${DEV_USER.email}`);
|
||||
console.log(` Password: ${DEV_USER.password}`);
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes('fetch')) {
|
||||
console.error('');
|
||||
console.error('❌ Could not connect to auth server!');
|
||||
console.error(' Make sure the auth server is running:');
|
||||
console.error(' pnpm dev:auth');
|
||||
console.error('');
|
||||
} else {
|
||||
console.error('❌ Error seeding dev user:', error);
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
await connection.end();
|
||||
}
|
||||
}
|
||||
|
||||
// Run the seed
|
||||
seedDevUser()
|
||||
.then(() => {
|
||||
process.exit(0);
|
||||
})
|
||||
.catch(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue