forked from spinspire/pocket-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.pb.ts
35 lines (31 loc) · 1.07 KB
/
main.pb.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Extending PocketBase with JS - @see https://pocketbase.io/docs/js-overview/
/// <reference path="../pb_data/types.d.ts" />
routerAdd("GET", "/api/goodbye/:name", (c) => {
let name = c.pathParam("name");
return c.json(200, { message: "Goodbye " + name });
});
// sends email to the logged in user
routerAdd(
"POST",
"/api/sendmail",
(c) => {
const user = c.get("authRecord"); // obtain user record from context
user.ignoreEmailVisibility(true); // required for user.get("email")
const address = user.get("email"); // works only after user.ignoreEmailVisibility(true)
const name = user.get("name");
const message = new MailerMessage({
from: {
address: $app.settings().meta.senderAddress,
name: $app.settings().meta.senderName,
},
to: [{ name, address }],
subject: `test email from ${name}`,
text: "Test email",
html: "<strong>Test</strong> <em>email</em>",
});
$app.newMailClient().send(message);
return c.json(200, { message });
},
// middleware(s)
$apis.requireRecordAuth("users")
);