Skip to content

Commit a230ecb

Browse files
committed
sendgrid
1 parent 671b265 commit a230ecb

File tree

7 files changed

+38
-216
lines changed

7 files changed

+38
-216
lines changed

.air.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exclude_dir = [
1414
"testdata",
1515
"public",
1616
"internal/sqlcdb",
17+
"cmd/app/sqlc",
1718
]
1819
exclude_file = []
1920
exclude_regex = ["_test.go"]

.env.sample

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# A Turso DB connection string
2+
SQLURL=
3+
# A SendGrid API key
4+
SENDGRID_API_KEY=
5+
# DEV or PROD
6+
PLATFORM=DEV
7+
# Use a random UUID for testing
8+
JWT_SECRET=

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
# learntocodefyi
1+
# learntocodefyi
2+
3+
To develop locally, run:
4+
5+
```bash
6+
cp .env.sample .env
7+
```
8+
9+
Then edit `.env` to use your own values.
10+
11+
Finally, run the local development script:
12+
13+
```bash
14+
./dev.sh
15+
```
16+
17+
Server will auto-restart on most file changes.

cmd/app/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func main() {
4848
if sqlURL == "" {
4949
log.Fatal("No SQLURL set in .env")
5050
}
51+
sendgridAPIKey := os.Getenv("SENDGRID_API_KEY")
52+
if sendgridAPIKey == "" {
53+
log.Fatal("No SENDGRID_API_KEY set in .env")
54+
}
5155
db, err := sql.Open("libsql", sqlURL)
5256
if err != nil {
5357
log.Fatal("error opening database: ", err)
@@ -67,7 +71,7 @@ func main() {
6771
log.Fatal("error parsing templates: ", err)
6872
}
6973

70-
sendgridClient := sendgridwrap.NewClient("", os.Getenv("PLATFORM"))
74+
sendgridClient := sendgridwrap.NewClient(sendgridAPIKey, os.Getenv("PLATFORM"))
7175
hs := handlerState{
7276
queries: queries,
7377
templates: templates,

cmd/app/public/styles.css

Lines changed: 0 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -729,213 +729,6 @@ select {
729729
--tw-backdrop-sepia: ;
730730
}
731731

732-
.mx-auto {
733-
margin-left: auto;
734-
margin-right: auto;
735-
}
736-
737-
.my-4 {
738-
margin-top: 1rem;
739-
margin-bottom: 1rem;
740-
}
741-
742-
.mb-2 {
743-
margin-bottom: 0.5rem;
744-
}
745-
746-
.mb-4 {
747-
margin-bottom: 1rem;
748-
}
749-
750-
.ml-2 {
751-
margin-left: 0.5rem;
752-
}
753-
754-
.flex {
755-
display: flex;
756-
}
757-
758-
.hidden {
759-
display: none;
760-
}
761-
762-
.w-full {
763-
width: 100%;
764-
}
765-
766-
.max-w-2xl {
767-
max-width: 42rem;
768-
}
769-
770-
.max-w-xl {
771-
max-width: 36rem;
772-
}
773-
774-
.flex-col {
775-
flex-direction: column;
776-
}
777-
778-
.items-center {
779-
align-items: center;
780-
}
781-
782-
.gap-2 {
783-
gap: 0.5rem;
784-
}
785-
786-
.gap-4 {
787-
gap: 1rem;
788-
}
789-
790-
.gap-8 {
791-
gap: 2rem;
792-
}
793-
794-
.space-y-4 > :not([hidden]) ~ :not([hidden]) {
795-
--tw-space-y-reverse: 0;
796-
margin-top: calc(1rem * calc(1 - var(--tw-space-y-reverse)));
797-
margin-bottom: calc(1rem * var(--tw-space-y-reverse));
798-
}
799-
800-
.overflow-y-auto {
801-
overflow-y: auto;
802-
}
803-
804-
.rounded {
805-
border-radius: 0.25rem;
806-
}
807-
808-
.rounded-lg {
809-
border-radius: 0.5rem;
810-
}
811-
812-
.border {
813-
border-width: 1px;
814-
}
815-
816-
.border-gray-500 {
817-
--tw-border-opacity: 1;
818-
border-color: rgb(107 114 128 / var(--tw-border-opacity));
819-
}
820-
821-
.bg-blue-500 {
822-
--tw-bg-opacity: 1;
823-
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
824-
}
825-
826-
.bg-gray-700 {
827-
--tw-bg-opacity: 1;
828-
background-color: rgb(55 65 81 / var(--tw-bg-opacity));
829-
}
830-
831-
.bg-gray-800 {
832-
--tw-bg-opacity: 1;
833-
background-color: rgb(31 41 55 / var(--tw-bg-opacity));
834-
}
835-
836-
.bg-gray-900 {
837-
--tw-bg-opacity: 1;
838-
background-color: rgb(17 24 39 / var(--tw-bg-opacity));
839-
}
840-
841-
.p-2 {
842-
padding: 0.5rem;
843-
}
844-
845-
.p-4 {
846-
padding: 1rem;
847-
}
848-
849-
.p-6 {
850-
padding: 1.5rem;
851-
}
852-
853-
.text-center {
854-
text-align: center;
855-
}
856-
857-
.text-2xl {
858-
font-size: 1.5rem;
859-
line-height: 2rem;
860-
}
861-
862-
.text-4xl {
863-
font-size: 2.25rem;
864-
line-height: 2.5rem;
865-
}
866-
867-
.text-lg {
868-
font-size: 1.125rem;
869-
line-height: 1.75rem;
870-
}
871-
872-
.text-sm {
873-
font-size: 0.875rem;
874-
line-height: 1.25rem;
875-
}
876-
877-
.text-xl {
878-
font-size: 1.25rem;
879-
line-height: 1.75rem;
880-
}
881-
882-
.font-semibold {
883-
font-weight: 600;
884-
}
885-
886-
.italic {
887-
font-style: italic;
888-
}
889-
890-
.leading-none {
891-
line-height: 1;
892-
}
893-
894-
.tracking-tight {
895-
letter-spacing: -0.025em;
896-
}
897-
898-
.text-gray-200 {
899-
--tw-text-opacity: 1;
900-
color: rgb(229 231 235 / var(--tw-text-opacity));
901-
}
902-
903-
.text-gray-300 {
904-
--tw-text-opacity: 1;
905-
color: rgb(209 213 219 / var(--tw-text-opacity));
906-
}
907-
908-
.text-gray-400 {
909-
--tw-text-opacity: 1;
910-
color: rgb(156 163 175 / var(--tw-text-opacity));
911-
}
912-
913-
.text-gray-500 {
914-
--tw-text-opacity: 1;
915-
color: rgb(107 114 128 / var(--tw-text-opacity));
916-
}
917-
918-
.text-white {
919-
--tw-text-opacity: 1;
920-
color: rgb(255 255 255 / var(--tw-text-opacity));
921-
}
922-
923-
.underline {
924-
text-decoration-line: underline;
925-
}
926-
927-
.shadow-lg {
928-
--tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
929-
--tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);
930-
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
931-
}
932-
933-
.shadow-sm {
934-
--tw-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
935-
--tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color);
936-
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
937-
}
938-
939732
.textlink {
940733
--tw-text-opacity: 1;
941734
color: rgb(59 130 246 / var(--tw-text-opacity));
@@ -946,8 +739,3 @@ select {
946739
--tw-text-opacity: 1;
947740
color: rgb(96 165 250 / var(--tw-text-opacity));
948741
}
949-
950-
.hover\:bg-blue-600:hover {
951-
--tw-bg-opacity: 1;
952-
background-color: rgb(37 99 235 / var(--tw-bg-opacity));
953-
}

internal/sendgridwrap/sendgrid.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,15 @@ func (c Client) SendMagicLink(toEmail, toName, loginLink string) error {
7777
request := sendgrid.GetRequest(c.APIKey, "/v3/mail/send", host)
7878
request.Method = "POST"
7979
request.Body = mail.GetRequestBody(m)
80-
_, err := sendgrid.MakeRequest(request)
80+
resp, err := sendgrid.MakeRequest(request)
8181
if err != nil {
8282
return err
8383
}
84+
85+
if resp.StatusCode > 299 {
86+
return fmt.Errorf("bad response from sendgrid. code: %v, body %v", resp.StatusCode, resp.Body)
87+
}
88+
8489
return nil
8590
}
8691

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"tailwindcss": "^3.3.5"
44
},
55
"scripts": {
6-
"tailwind": "tailwindcss -i 'styles.css' -o 'public/styles.css'"
6+
"tailwind": "tailwindcss -i 'styles.css' -o 'cmd/app/public/styles.css'"
77
},
88
"devDependencies": {
99
"@tailwindcss/forms": "^0.5.7"

0 commit comments

Comments
 (0)