Update email verification and password reset flows; refactor Docker Compose and enhance email management
This commit is contained in:
37
frontend/src/routes/user/reset-password/+page.server.ts
Normal file
37
frontend/src/routes/user/reset-password/+page.server.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { fetchCSRFToken } from '$lib/index.server';
|
||||
import { fail, type Actions } from '@sveltejs/kit';
|
||||
|
||||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||
|
||||
export const actions: Actions = {
|
||||
forgotPassword: async (event) => {
|
||||
const formData = await event.request.formData();
|
||||
|
||||
const email = formData.get('email') as string | null | undefined;
|
||||
|
||||
if (!email) {
|
||||
return fail(400, { message: 'missing_email' });
|
||||
}
|
||||
|
||||
let csrfToken = await fetchCSRFToken();
|
||||
|
||||
let res = await fetch(`${endpoint}/_allauth/browser/v1/auth/password/request`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken,
|
||||
Cookie: `csrftoken=${csrfToken}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
email
|
||||
})
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
let message = await res.json();
|
||||
return fail(res.status, message);
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user