Skip to content

Commit

Permalink
sendgrid
Browse files Browse the repository at this point in the history
  • Loading branch information
wagslane committed Jan 3, 2024
1 parent 671b265 commit a230ecb
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 216 deletions.
1 change: 1 addition & 0 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exclude_dir = [
"testdata",
"public",
"internal/sqlcdb",
"cmd/app/sqlc",
]
exclude_file = []
exclude_regex = ["_test.go"]
Expand Down
8 changes: 8 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# A Turso DB connection string
SQLURL=
# A SendGrid API key
SENDGRID_API_KEY=
# DEV or PROD
PLATFORM=DEV
# Use a random UUID for testing
JWT_SECRET=
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# learntocodefyi
# learntocodefyi

To develop locally, run:

```bash
cp .env.sample .env
```

Then edit `.env` to use your own values.

Finally, run the local development script:

```bash
./dev.sh
```

Server will auto-restart on most file changes.
6 changes: 5 additions & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func main() {
if sqlURL == "" {
log.Fatal("No SQLURL set in .env")
}
sendgridAPIKey := os.Getenv("SENDGRID_API_KEY")
if sendgridAPIKey == "" {
log.Fatal("No SENDGRID_API_KEY set in .env")
}
db, err := sql.Open("libsql", sqlURL)
if err != nil {
log.Fatal("error opening database: ", err)
Expand All @@ -67,7 +71,7 @@ func main() {
log.Fatal("error parsing templates: ", err)
}

sendgridClient := sendgridwrap.NewClient("", os.Getenv("PLATFORM"))
sendgridClient := sendgridwrap.NewClient(sendgridAPIKey, os.Getenv("PLATFORM"))
hs := handlerState{
queries: queries,
templates: templates,
Expand Down
212 changes: 0 additions & 212 deletions cmd/app/public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -729,213 +729,6 @@ select {
--tw-backdrop-sepia: ;
}

.mx-auto {
margin-left: auto;
margin-right: auto;
}

.my-4 {
margin-top: 1rem;
margin-bottom: 1rem;
}

.mb-2 {
margin-bottom: 0.5rem;
}

.mb-4 {
margin-bottom: 1rem;
}

.ml-2 {
margin-left: 0.5rem;
}

.flex {
display: flex;
}

.hidden {
display: none;
}

.w-full {
width: 100%;
}

.max-w-2xl {
max-width: 42rem;
}

.max-w-xl {
max-width: 36rem;
}

.flex-col {
flex-direction: column;
}

.items-center {
align-items: center;
}

.gap-2 {
gap: 0.5rem;
}

.gap-4 {
gap: 1rem;
}

.gap-8 {
gap: 2rem;
}

.space-y-4 > :not([hidden]) ~ :not([hidden]) {
--tw-space-y-reverse: 0;
margin-top: calc(1rem * calc(1 - var(--tw-space-y-reverse)));
margin-bottom: calc(1rem * var(--tw-space-y-reverse));
}

.overflow-y-auto {
overflow-y: auto;
}

.rounded {
border-radius: 0.25rem;
}

.rounded-lg {
border-radius: 0.5rem;
}

.border {
border-width: 1px;
}

.border-gray-500 {
--tw-border-opacity: 1;
border-color: rgb(107 114 128 / var(--tw-border-opacity));
}

.bg-blue-500 {
--tw-bg-opacity: 1;
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
}

.bg-gray-700 {
--tw-bg-opacity: 1;
background-color: rgb(55 65 81 / var(--tw-bg-opacity));
}

.bg-gray-800 {
--tw-bg-opacity: 1;
background-color: rgb(31 41 55 / var(--tw-bg-opacity));
}

.bg-gray-900 {
--tw-bg-opacity: 1;
background-color: rgb(17 24 39 / var(--tw-bg-opacity));
}

.p-2 {
padding: 0.5rem;
}

.p-4 {
padding: 1rem;
}

.p-6 {
padding: 1.5rem;
}

.text-center {
text-align: center;
}

.text-2xl {
font-size: 1.5rem;
line-height: 2rem;
}

.text-4xl {
font-size: 2.25rem;
line-height: 2.5rem;
}

.text-lg {
font-size: 1.125rem;
line-height: 1.75rem;
}

.text-sm {
font-size: 0.875rem;
line-height: 1.25rem;
}

.text-xl {
font-size: 1.25rem;
line-height: 1.75rem;
}

.font-semibold {
font-weight: 600;
}

.italic {
font-style: italic;
}

.leading-none {
line-height: 1;
}

.tracking-tight {
letter-spacing: -0.025em;
}

.text-gray-200 {
--tw-text-opacity: 1;
color: rgb(229 231 235 / var(--tw-text-opacity));
}

.text-gray-300 {
--tw-text-opacity: 1;
color: rgb(209 213 219 / var(--tw-text-opacity));
}

.text-gray-400 {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
}

.text-gray-500 {
--tw-text-opacity: 1;
color: rgb(107 114 128 / var(--tw-text-opacity));
}

.text-white {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}

.underline {
text-decoration-line: underline;
}

.shadow-lg {
--tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}

.shadow-sm {
--tw-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
--tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}

.textlink {
--tw-text-opacity: 1;
color: rgb(59 130 246 / var(--tw-text-opacity));
Expand All @@ -946,8 +739,3 @@ select {
--tw-text-opacity: 1;
color: rgb(96 165 250 / var(--tw-text-opacity));
}

.hover\:bg-blue-600:hover {
--tw-bg-opacity: 1;
background-color: rgb(37 99 235 / var(--tw-bg-opacity));
}
7 changes: 6 additions & 1 deletion internal/sendgridwrap/sendgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ func (c Client) SendMagicLink(toEmail, toName, loginLink string) error {
request := sendgrid.GetRequest(c.APIKey, "/v3/mail/send", host)
request.Method = "POST"
request.Body = mail.GetRequestBody(m)
_, err := sendgrid.MakeRequest(request)
resp, err := sendgrid.MakeRequest(request)
if err != nil {
return err
}

if resp.StatusCode > 299 {
return fmt.Errorf("bad response from sendgrid. code: %v, body %v", resp.StatusCode, resp.Body)
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tailwindcss": "^3.3.5"
},
"scripts": {
"tailwind": "tailwindcss -i 'styles.css' -o 'public/styles.css'"
"tailwind": "tailwindcss -i 'styles.css' -o 'cmd/app/public/styles.css'"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.7"
Expand Down

0 comments on commit a230ecb

Please sign in to comment.