diff --git a/src/app/api/schema.ts b/src/app/api/schema.ts index da176b8..b809ef0 100644 --- a/src/app/api/schema.ts +++ b/src/app/api/schema.ts @@ -188,8 +188,7 @@ export interface paths { requestBody: { content: { 'multipart/form-data': { - /** Format: binary */ - file?: string + file?: components['schemas']['IFormFile'] } } } @@ -502,6 +501,8 @@ export interface components { DeletePostReactionRequest: { emoji: string } + /** Format: binary */ + IFormFile: string ListSignupCodesResult: { signupCodes: components['schemas']['SignupCodeDto'][] } @@ -513,6 +514,7 @@ export interface components { LoginRequest: { username: string password: string + rememberMe: boolean | null } LoginResponse: { /** Format: uuid */ @@ -560,7 +562,7 @@ export interface components { username: string password: string signupCode: string - email: string | null + rememberMe: boolean | null } RegisterResponse: { /** Format: uuid */ diff --git a/src/app/auth/authService.ts b/src/app/auth/authService.ts index 51e56fa..64f1dcd 100644 --- a/src/app/auth/authService.ts +++ b/src/app/auth/authService.ts @@ -6,9 +6,9 @@ import { ApiClient } from '../api/client.ts' export class AuthService { constructor(private readonly client: ApiClient) {} - async login(username: string, password: string) { + async login(username: string, password: string, rememberMe: boolean = false) { const res = await this.client.POST('/auth/login', { - body: { username, password }, + body: { username, password, rememberMe }, credentials: 'include', }) @@ -19,9 +19,9 @@ export class AuthService { dispatchMessage('auth:logged-in', null) } - async signup(username: string, password: string, signupCode: string) { + async signup(username: string, password: string, signupCode: string, rememberMe: boolean = false) { const res = await this.client.POST('/auth/register', { - body: { username, password, signupCode, email: null }, + body: { username, password, signupCode, email: null, rememberMe }, credentials: 'include', }) diff --git a/src/app/auth/pages/LoginPage.tsx b/src/app/auth/pages/LoginPage.tsx index 5163d71..16d1a3f 100644 --- a/src/app/auth/pages/LoginPage.tsx +++ b/src/app/auth/pages/LoginPage.tsx @@ -17,6 +17,7 @@ export default function LoginPage({ authService }: LoginPageProps) { const [isSubmitting, setIsSubmitting] = useState(false) const [username, setUsername] = useState('') const [password, setPassword] = useState('') + const [rememberMe, setRememberMe] = useState(false) const [error, setError] = useState(null) const usernameInputRef = useRef(null) const passwordInputRef = useRef(null) @@ -49,7 +50,7 @@ export default function LoginPage({ authService }: LoginPageProps) { setIsSubmitting(true) try { - await authService.login(username, password) + await authService.login(username, password, rememberMe) } catch (error: unknown) { setError(error instanceof Error ? error.message : 'something went terribly wrong') } finally { @@ -95,6 +96,19 @@ export default function LoginPage({ authService }: LoginPageProps) { /> +
+ setRememberMe(e.target.checked)} + className="h-4 w-4" + /> + +
+ diff --git a/src/app/auth/pages/SignupPage.tsx b/src/app/auth/pages/SignupPage.tsx index 19b2ab4..ab6b376 100644 --- a/src/app/auth/pages/SignupPage.tsx +++ b/src/app/auth/pages/SignupPage.tsx @@ -20,6 +20,7 @@ export default function SignupPage({ authService }: SignupPageProps) { const { code } = useParams() const [signupCode, setSignupCode] = useState(null) const [isSubmitting, setIsSubmitting] = useState(false) + const [rememberMe, setRememberMe] = useState(false) const [error, setError] = useState('') const [username, setUsername, usernameError, validateUsername] = useValidatedInput(isValidUsername) @@ -79,7 +80,7 @@ export default function SignupPage({ authService }: SignupPageProps) { setIsSubmitting(true) try { - await authService.signup(username, password, signupCode) + await authService.signup(username, password, signupCode, rememberMe) navigate('/') } catch (e: unknown) { const err = e as Error @@ -116,6 +117,18 @@ export default function SignupPage({ authService }: SignupPageProps) { type="password" ref={passwordInputRef} /> +
+ setRememberMe(e.target.checked)} + className="h-4 w-4" + /> + +