2a6629af79
Cloud saves were fully built but never wired up — useCloudSave() hook was never called, no load-from-cloud flow existed, and there was no way to continue a saved game. Logout was completely missing (no endpoint, no UI). Accounts felt like a gate behind the invite wall rather than real accounts. Backend: add tokenVersion to users for server-side token invalidation, POST /auth/logout bumps it to revoke all JWTs, GET /auth/me returns profile, GET /saves/latest returns most recent save with full gameData. All createToken calls now include tokenVersion. Auth middleware rejects tokens with stale tokenVersion. Frontend: wire up useCloudSave() in App (auto-saves every 60 ticks with error handling), fetch cloud save on startup for registered users, show "Continue Your Game" card on NewGameScreen, add Log Out button with confirmation in Settings, show username in sidebar, 401 interceptor clears auth and reloads. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
60 lines
2.5 KiB
TypeScript
60 lines
2.5 KiB
TypeScript
import { pgTable, uuid, text, timestamp, jsonb, integer, boolean, index } from 'drizzle-orm/pg-core';
|
|
|
|
export const users = pgTable('users', {
|
|
id: uuid('id').defaultRandom().primaryKey(),
|
|
anonToken: uuid('anon_token').defaultRandom().notNull().unique(),
|
|
username: text('username').unique(),
|
|
email: text('email').unique(),
|
|
passwordHash: text('password_hash'),
|
|
role: text('role').notNull().default('user'),
|
|
mustResetPassword: boolean('must_reset_password').notNull().default(false),
|
|
tokenVersion: integer('token_version').notNull().default(0),
|
|
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
lastSeenAt: timestamp('last_seen_at').defaultNow().notNull(),
|
|
});
|
|
|
|
export const saves = pgTable('saves', {
|
|
id: uuid('id').defaultRandom().primaryKey(),
|
|
userId: uuid('user_id').notNull().references(() => users.id),
|
|
companyName: text('company_name').notNull(),
|
|
saveVersion: integer('save_version').notNull(),
|
|
gameData: jsonb('game_data').notNull(),
|
|
tickCount: integer('tick_count').notNull().default(0),
|
|
era: text('era').notNull().default('startup'),
|
|
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
|
}, (table) => [
|
|
index('saves_user_id_idx').on(table.userId),
|
|
]);
|
|
|
|
export const leaderboard = pgTable('leaderboard', {
|
|
id: uuid('id').defaultRandom().primaryKey(),
|
|
userId: uuid('user_id').notNull().references(() => users.id),
|
|
companyName: text('company_name').notNull(),
|
|
category: text('category').notNull(),
|
|
score: integer('score').notNull(),
|
|
era: text('era').notNull(),
|
|
tickCount: integer('tick_count').notNull(),
|
|
submittedAt: timestamp('submitted_at').defaultNow().notNull(),
|
|
}, (table) => [
|
|
index('leaderboard_category_score_idx').on(table.category, table.score),
|
|
]);
|
|
|
|
export const achievements = pgTable('achievements', {
|
|
id: uuid('id').defaultRandom().primaryKey(),
|
|
userId: uuid('user_id').notNull().references(() => users.id),
|
|
achievementId: text('achievement_id').notNull(),
|
|
unlockedAt: timestamp('unlocked_at').defaultNow().notNull(),
|
|
}, (table) => [
|
|
index('achievements_user_id_idx').on(table.userId),
|
|
]);
|
|
|
|
export const invitations = pgTable('invitations', {
|
|
id: uuid('id').defaultRandom().primaryKey(),
|
|
code: text('code').notNull().unique(),
|
|
createdBy: uuid('created_by').notNull().references(() => users.id),
|
|
usedBy: uuid('used_by').references(() => users.id),
|
|
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
expiresAt: timestamp('expires_at'),
|
|
});
|