Skip to content

Commit a1392e1

Browse files
committed
Share common data types with frontend.
1 parent 0572c64 commit a1392e1

3 files changed

Lines changed: 11 additions & 32 deletions

File tree

src/public/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { initializeDatabase } from "../server/db";
1+
import type { UserInfo } from "../common/types.ts";
22

33
/**
44
* Hides all screens and shows only the specified one.
@@ -69,17 +69,19 @@ function initializeUI() {
6969
const messageElement = document.getElementById('register-message');
7070
messageElement.textContent = '';
7171
messageElement.classList.remove('error');
72-
const alias = registerForm.elements['alias'].value.trim();
73-
const email = registerForm.elements['email'].value.trim();
74-
const password = registerForm.elements['password'].value;
7572
registerForm.classList.add('loading');
76-
const response = await fetch('/api/register', {
73+
let response = await fetch('/api/register', {
7774
method: 'POST',
7875
body: new FormData(registerForm)
7976
});
8077

8178
if (response.ok) {
82-
messageElement.textContent = `Registration successful for ${email}! Redirecting to login...`;
79+
messageElement.textContent = `Registration successful! Redirecting to profile...`;
80+
response = await fetch('/api/userinfo');
81+
if (response.ok) {
82+
const userInfo = await response.json() as UserInfo;
83+
console.log('Registered user info:', userInfo);
84+
}
8385
//await new Promise(resolve => setTimeout(resolve, 1500));
8486
//showView('login-screen');
8587
} else {

src/server/db.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
import { readFileSync } from 'fs';
22
import type { PGInterface } from './types.ts';
3+
import type { User, Session } from '../common/types.ts';
34

4-
export interface User {
5-
id: number;
6-
email: string | null;
7-
username: string;
8-
hashed_password: string | null;
9-
alias: string;
10-
verification_email: string | null;
11-
created_ip_address: string;
12-
created_at: Date;
13-
active_at: Date;
14-
};
155
export interface VerificationEmail {
166
email: string;
177
verification_code: string;
188
created_at: Date;
199
};
20-
export interface Session {
21-
id: number;
22-
session_key?: string;
23-
url?: string;
24-
user_id: number;
25-
created_at: Date;
26-
active_ip_address: string;
27-
updated_at: Date;
28-
};
2910

3011
export async function cleanupDatabase(client: PGInterface) {
3112
const sqlTables = [

src/server/user.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import type { ClockAPI } from '../common/interfaces.ts';
33
import type { PGInterface } from './types.ts';
44
import type { TransportInterface, LimitsConfig } from './server.ts';
55
import { randomBytes } from 'crypto';
6-
import type { User, VerificationEmail, Session } from './db.ts';
6+
import type { UserInfo, User, Session } from '../common/types.ts';
7+
import type { VerificationEmail } from './db.ts';
78

89
export type RegistrationData = {
910
username: string | null;
@@ -34,11 +35,6 @@ export type AuthenticationHandlerConfig = {
3435
limits: LimitsConfig;
3536
}
3637

37-
export type UserInfo = {
38-
user: User;
39-
sessions: Session[];
40-
}
41-
4238
const SALT_ROUNDS = 12;
4339

4440
function generateSessionId() {

0 commit comments

Comments
 (0)