Replace the header "Byt lösenord" link with an Inställningar menu for changing email or password. Email changes are two-step: request with password, confirmation link to the new address, then password again on confirm so a wrong inbox cannot take over the account. - Backend: EmailChangeService, V10 email_change_tokens, confirm API - Frontend: ChangeEmailPage, ConfirmEmailChangePage, header dropdown - E2E: account-settings round-trips, Mailpit verification, wrong-password guard - Flyway: V9 restore for dev DBs, CI migration checks, V10 for email tokens Co-authored-by: Cursor <cursoragent@cursor.com>
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
import { request } from './client'
|
|
|
|
export interface AuthResponse {
|
|
token: string
|
|
}
|
|
|
|
export function register(
|
|
email: string,
|
|
password: string,
|
|
): Promise<AuthResponse> {
|
|
return request<AuthResponse>('/auth/register', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ email, password }),
|
|
})
|
|
}
|
|
|
|
export function login(email: string, password: string): Promise<AuthResponse> {
|
|
return request<AuthResponse>('/auth/login', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ email, password }),
|
|
})
|
|
}
|
|
|
|
export interface MessageResponse {
|
|
message: string
|
|
}
|
|
|
|
/** Optional testToken is returned only when backend expose-token is enabled (E2E). */
|
|
export interface ChangeEmailResponse extends MessageResponse {
|
|
testToken?: string
|
|
}
|
|
|
|
/** Optional testToken is returned only when backend expose-token is enabled (E2E). */
|
|
export interface ForgotPasswordResponse extends MessageResponse {
|
|
testToken?: string
|
|
}
|
|
|
|
export function forgotPassword(email: string): Promise<ForgotPasswordResponse> {
|
|
return request<ForgotPasswordResponse>('/auth/forgot-password', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ email }),
|
|
})
|
|
}
|
|
|
|
export function resetPassword(
|
|
token: string,
|
|
password: string,
|
|
): Promise<MessageResponse> {
|
|
return request<MessageResponse>('/auth/reset-password', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ token, password }),
|
|
})
|
|
}
|
|
|
|
export function changePassword(
|
|
currentPassword: string,
|
|
newPassword: string,
|
|
): Promise<MessageResponse> {
|
|
return request<MessageResponse>('/auth/change-password', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ currentPassword, newPassword }),
|
|
})
|
|
}
|
|
|
|
export function changeEmail(
|
|
newEmail: string,
|
|
password: string,
|
|
): Promise<ChangeEmailResponse> {
|
|
return request<ChangeEmailResponse>('/auth/change-email', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ newEmail, password }),
|
|
})
|
|
}
|
|
|
|
export function confirmEmailChange(
|
|
token: string,
|
|
password: string,
|
|
): Promise<AuthResponse> {
|
|
return request<AuthResponse>('/auth/confirm-email-change', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ token, password }),
|
|
})
|
|
}
|