Skip to content

Commit 355f360

Browse files
committed
Add form actions
Because for some reason, PB adds query string params to body payload. pocketbase/pocketbase#6875
1 parent 00647c6 commit 355f360

File tree

8 files changed

+47
-45
lines changed

8 files changed

+47
-45
lines changed

pb_hooks/pages/account/change-email/index.ejs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@
3535
3636
let serverError = null
3737
let fieldErrors = {}
38-
let data = {}
38+
let parsedFormData = {}
3939
4040
if (request.method === 'POST') {
4141
42-
data = formData();
42+
parsedFormData = formData();
4343
44-
const validation = validateFormWithSchema(data, loginSchema, ajv, dbg);
44+
const validation = validateFormWithSchema(parsedFormData, loginSchema, ajv, dbg);
4545
if (!validation.valid) {
4646
fieldErrors = validation.fieldErrors;
4747
serverError = validation.serverError;
4848
} else {
4949
try {
50-
const user = pb({ request }).collection('users').requestEmailChange(data.identity)
50+
const user = pb({ request }).collection('users').requestEmailChange(parsedFormData.identity)
5151
redirect(`/`, {
5252
message: 'Email change requested, please check your email.',
5353
})
@@ -60,7 +60,7 @@
6060
}
6161
</script>
6262

63-
<form method="post" class="p-6 max-w-sm mx-auto">
63+
<form method="post" action="/account/change-email" class="p-6 max-w-sm mx-auto">
6464
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
6565

6666
<%- include('server-error', { serverError }) %>
@@ -70,7 +70,7 @@
7070
<label class="label">Email</label>
7171
<input
7272
name="identity"
73-
value="<%= data.identity %>"
73+
value="<%= parsedFormData.identity %>"
7474
type="email"
7575
class="validator input<%= fieldErrors && fieldErrors.identity ? ' input-error' : '' %>"
7676
placeholder="Email"

pb_hooks/pages/account/change-password/index.ejs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
type: 'string',
3535
minLength: 8,
3636
maxLength: 71,
37-
}
37+
},
3838
},
3939
errorMessage: {
4040
type: 'Invalid data type',
@@ -54,13 +54,13 @@
5454
5555
let serverError = null
5656
let fieldErrors = {}
57-
let data = {}
57+
let parsedFormData = {}
5858
5959
if (request.method === 'POST') {
6060
61-
data = formData();
61+
parsedFormData = formData();
6262
63-
const validation = validateFormWithSchema(data, loginSchema, ajv, dbg);
63+
const validation = validateFormWithSchema(parsedFormData, loginSchema, ajv, dbg);
6464
if (!validation.valid) {
6565
fieldErrors = validation.fieldErrors;
6666
serverError = validation.serverError;
@@ -72,7 +72,7 @@
7272
passwordConfirm: confirmPassword,
7373
})
7474
75-
redirect(`/`, {
75+
redirect(`/auth/login`, {
7676
message: 'Password changed successfully, you will need to login again.',
7777
})
7878
} catch (e) {
@@ -84,7 +84,7 @@
8484
}
8585
</script>
8686

87-
<form method="post" class="p-6 max-w-sm mx-auto">
87+
<form method="post" action="/account/change-password" class="p-6 max-w-sm mx-auto">
8888
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
8989

9090
<%- include('server-error', { serverError }) %>

pb_hooks/pages/account/logout/index.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<%- include('server-error', { serverError }) %>
1414

15-
<form method="post" class="p-6 max-w-sm mx-auto space-y-4">
15+
<form method="post" action="/account/logout" class="p-6 max-w-sm mx-auto space-y-4">
1616
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
1717

1818
<legend class="fieldset-legend">Logout</legend>

pb_hooks/pages/auth/confirm/email-change/[token].ejs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@
4040
4141
let serverError = null
4242
let fieldErrors = {}
43-
let data = {}
43+
let parsedFormData = {}
4444
4545
if (request.method === 'POST') {
4646
47-
data = formData();
47+
parsedFormData = formData();
4848
49-
const validation = validateFormWithSchema(data, loginSchema, ajv, dbg);
49+
const validation = validateFormWithSchema(parsedFormData, loginSchema, ajv, dbg);
5050
if (!validation.valid) {
5151
fieldErrors = validation.fieldErrors;
5252
serverError = validation.serverError;
5353
} else {
5454
try {
55-
pb().collection('users').confirmEmailChange(token, data.password);
55+
pb().collection('users').confirmEmailChange(token, parsedFormData.password);
5656
redirect('/auth/login', {
5757
message: 'Your email has been changed. You will need to login again.',
5858
})
@@ -65,7 +65,7 @@
6565
}
6666
</script>
6767

68-
<form method="post" class="p-6 max-w-sm mx-auto">
68+
<form method="post" action="/auth/confirm/email-change" class="p-6 max-w-sm mx-auto">
6969
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
7070

7171
<%- include('server-error', { serverError }) %>

pb_hooks/pages/auth/confirm/password-reset/[token].ejs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
type: 'string',
3030
minLength: 8,
3131
maxLength: 71,
32-
}
32+
},
3333
},
3434
errorMessage: {
3535
type: 'Invalid data type',
@@ -47,22 +47,22 @@
4747
4848
let serverError = null
4949
let fieldErrors = {}
50-
let data = {}
50+
let parsedFormData = {}
5151
5252
if (request.method === 'POST') {
5353
54-
data = formData();
54+
parsedFormData = formData();
5555
56-
const validation = validateFormWithSchema(data, loginSchema, ajv, dbg);
56+
const validation = validateFormWithSchema(parsedFormData, loginSchema, ajv, dbg);
5757
if (!validation.valid) {
5858
fieldErrors = validation.fieldErrors;
5959
serverError = validation.serverError;
6060
} else {
6161
try {
6262
pb().collection('users').confirmPasswordReset(
6363
token,
64-
data.password,
65-
data.confirmPassword,
64+
parsedFormData.password,
65+
parsedFormData.confirmPassword,
6666
);
6767
redirect('/auth/login', {
6868
message: 'Your password has been reset, you can now login.',
@@ -76,7 +76,7 @@
7676
}
7777
</script>
7878

79-
<form method="post" class="p-6 max-w-sm mx-auto">
79+
<form method="post" action="/auth/confirm/password-reset" class="p-6 max-w-sm mx-auto">
8080
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
8181

8282
<%- include('server-error', { serverError }) %>

pb_hooks/pages/auth/forgot/index.ejs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@
3535
3636
let serverError = null
3737
let fieldErrors = {}
38-
let data = {}
38+
let parsedFormData = {}
3939
4040
if (request.method === 'POST') {
4141
42-
data = formData();
42+
parsedFormData = formData();
4343
44-
const validation = validateFormWithSchema(data, loginSchema, ajv, dbg);
44+
const validation = validateFormWithSchema(parsedFormData, loginSchema, ajv, dbg);
4545
if (!validation.valid) {
4646
fieldErrors = validation.fieldErrors;
4747
serverError = validation.serverError;
4848
} else {
4949
try {
50-
pb().collection('users').requestPasswordReset(data.email);
50+
pb().collection('users').requestPasswordReset(parsedFormData.email);
5151
redirect(`/`, {
5252
message: 'Password reset email sent, please check your inbox.',
5353
})
@@ -60,7 +60,7 @@
6060
}
6161
</script>
6262

63-
<form method="post" class="p-6 max-w-sm mx-auto">
63+
<form method="post" action="/auth/forgot" class="p-6 max-w-sm mx-auto">
6464
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
6565

6666
<%- include('server-error', { serverError }) %>
@@ -70,7 +70,7 @@
7070
<label class="label">Email</label>
7171
<input
7272
name="identity"
73-
value="<%= data.identity %>"
73+
value="<%= parsedFormData.identity %>"
7474
type="email"
7575
class="validator input<%= fieldErrors && fieldErrors.identity ? ' input-error' : '' %>"
7676
placeholder="Email"

pb_hooks/pages/auth/login/index.ejs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
type: 'string',
2525
minLength: 8,
2626
maxLength: 71,
27-
}
27+
},
2828
},
2929
errorMessage: {
3030
type: 'Invalid data type',
@@ -42,21 +42,23 @@
4242
4343
let serverError = null
4444
let fieldErrors = {}
45-
let data = {}
45+
let parsedFormData = {}
4646
4747
if (request.method === 'POST') {
4848
49-
data = formData();
49+
parsedFormData = formData();
50+
51+
echo(parsedFormData)
5052
51-
const validation = validateFormWithSchema(data, loginSchema, ajv);
53+
const validation = validateFormWithSchema(parsedFormData, loginSchema, ajv, dbg);
5254
if (!validation.valid) {
5355
fieldErrors = validation.fieldErrors;
5456
serverError = validation.serverError;
5557
} else {
5658
try {
5759
const authData = pb()
5860
.collection('users')
59-
.authWithPassword(data.identity, data.password);
61+
.authWithPassword(parsedFormData.identity, parsedFormData.password);
6062
if (authData.record.verified) {
6163
api.signIn(authData)
6264
redirect(`/`)
@@ -72,7 +74,7 @@
7274
}
7375
</script>
7476

75-
<form method="post" class="p-6 max-w-sm mx-auto">
77+
<form method="post" action="/auth/login" class="p-6 max-w-sm mx-auto">
7678
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
7779

7880
<%- include('server-error', { serverError }) %>
@@ -82,7 +84,7 @@
8284
<label class="label">Email</label>
8385
<input
8486
name="identity"
85-
value="<%= data.identity %>"
87+
value="<%= parsedFormData.identity %>"
8688
type="email"
8789
class="validator input<%= fieldErrors && fieldErrors.identity ? ' input-error' : '' %>"
8890
placeholder="Email"

pb_hooks/pages/auth/register/index.ejs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
type: 'string',
2525
minLength: 8,
2626
maxLength: 71,
27-
}
27+
},
2828
},
2929
errorMessage: {
3030
type: 'Invalid data type',
@@ -42,19 +42,19 @@
4242
4343
let serverError = null
4444
let fieldErrors = {}
45-
let data = {}
45+
let parsedFormData = {}
4646
4747
if (request.method === 'POST') {
4848
49-
data = formData();
49+
parsedFormData = formData();
5050
51-
const validation = validateFormWithSchema(data, loginSchema, ajv, dbg);
51+
const validation = validateFormWithSchema(parsedFormData, loginSchema, ajv, dbg);
5252
if (!validation.valid) {
5353
fieldErrors = validation.fieldErrors;
5454
serverError = validation.serverError;
5555
} else {
5656
try {
57-
createUser(data.identity, data.password)
57+
createUser(parsedFormData.identity, parsedFormData.password)
5858
redirect(`/`, {
5959
message: 'Registration successful. Please check your email to verify your account.'
6060
})
@@ -69,7 +69,7 @@
6969
}
7070
</script>
7171

72-
<form method="post" class="p-6 max-w-sm mx-auto">
72+
<form method="post" action="/auth/register" class="p-6 max-w-sm mx-auto">
7373
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
7474

7575
<%- include('server-error', { serverError }) %>
@@ -79,7 +79,7 @@
7979
<label class="label">Email</label>
8080
<input
8181
name="identity"
82-
value="<%= data.identity %>"
82+
value="<%= parsedFormData.identity %>"
8383
type="email"
8484
class="validator input<%= fieldErrors && fieldErrors.identity ? ' input-error' : '' %>"
8585
placeholder="Email"

0 commit comments

Comments
 (0)