Skip to content

Commit

Permalink
fix(console): mailpit and profile w.i.p
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Jun 20, 2024
1 parent af20e01 commit 45930fb
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 42 deletions.
54 changes: 19 additions & 35 deletions apps/console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ Everything you need to build a Svelte project, powered by [`create-svelte`](http

### First Step

download latest `traefik.me` certs for _svelte_ dev server.
1. download latest `traefik.me` certs for _svelte_ dev server.

> NOTE: they will expire every 60 days
> NOTE: they will expire every 60 days
```shell
curl traefik.me/fullchain.pem -o infra/base/traefik/certs/traefik.me.crt
curl traefik.me/privkey.pem -o infra/base/traefik/certs/traefik.me.key
# make sure docker has read access to those files:
chmod ugo+r infra/base/traefik/.htpasswd
```
```shell
curl traefik.me/fullchain.pem -o infra/base/traefik/certs/traefik.me.crt
curl traefik.me/privkey.pem -o infra/base/traefik/certs/traefik.me.key
# make sure docker has read access to those files:
chmod ugo+r infra/base/traefik/.htpasswd
```

2. Generate TLS `certs` to enable **TLS** transport for **Mailpit** and **Hasura-auth**

```shell
cd infra/base/mailpit
./create-certs.sh mailpit
chmod -R ugo+r certs
# go back to project root
cd ../../..
```

### Backend

Expand Down Expand Up @@ -105,32 +115,6 @@ crane export ghcr.io/xmlking/spectacular/console:v0.1.3 - | tar -tvf - | grep -v
| Dashboard | <https://dashboard.traefik.me> |
| Tailcall | <https://gateway.traefik.me> |

#### (Or) Start backend services with nhost cli

```shell
# start all
nhost up
# check logs for example: auth service
nhost logs auth -f
# shutdown all
nhost down
# (optional) shutdown and reset volume
nhost down --volumes
# (optional) nhost first time when started, will load seeds but you can force with `--apply-seeds`
nhost up --apply-seeds
```

| Service | URL |
| --------- | ------------------------------------------------- |
| Postgres | postgres://postgres:postgres@localhost:5432/local |
| Hasura | <https://local.hasura.nhost.run> |
| GraphQL | <https://local.graphql.nhost.run> |
| Auth | <https://local.auth.nhost.run> |
| Storage | <https://local.storage.nhost.run> |
| Functions | <https://local.functions.nhost.run/v1/echo> |
| Dashboard | <https://local.dashboard.nhost.run> |
| Mailhog | <https://local.mailhog.nhost.run> |

#### Apply seeds

Optionally apply all seed files
Expand All @@ -151,7 +135,7 @@ turbo dev
turbo dev --log-order=stream
# or run with `prod` profile and
# overload envelopment variables from `.env.prod`
NODE_ENV=prod turbo dev
turbo dev:prod --log-order=stream
```

Default demo user's **username:** `[email protected]` **password:** `sumodemo123`
Expand Down
5 changes: 5 additions & 0 deletions apps/console/src/routes/(app)/customers/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const rows = handler.getRows();
// $: handler.setRows(customers);
</script>

<svelte:head>
<title>Datablocks | Customer</title>
<meta name="description" content="Customer Table" />
</svelte:head>

<div class="page-container">
<div class="page-section">
<header class="flex justify-between">
Expand Down
72 changes: 72 additions & 0 deletions apps/console/src/routes/(app)/profile/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<script lang="ts">
import { Debug } from '@spectacular/skeleton/components';
import { Settings } from 'lucide-svelte';
import Cookies from 'js-cookie'
import { nhost, user } from '$lib/stores/user';
import { goto } from '$app/navigation';
import { NHOST_SESSION_KEY } from '$lib/constants.js';
import type { AuthErrorPayload } from '@nhost/nhost-js';
export let data
let email: string
let error: AuthErrorPayload | null
const handleSubmit = async () => {
const { session, error: signInError } = await nhost.auth.signUp({ email, securityKey: true })
if (session) {
Cookies.set(NHOST_SESSION_KEY, btoa(JSON.stringify(session)), { path: '/' })
goto('/protected/todos')
} else {
error = signInError
}
}
</script>

<svelte:head>
<title>Datablocks | Profile</title>
<meta name="description" content="Account Profile" />
</svelte:head>

<div class="page-container">
<div class="page-section">
<h2 class="h2">Profile</h2>
<Debug data={$user} />
</div>
<div class="page-section">
<h3 class="h3">WebAuthn</h3>
<div class="card p-4">
<title>Security keys</title>
<table >
<colgroup>
<col />
<col width="20%" />
</colgroup>
<!-- <tbody>
{list.map(({ id, nickname }) => (
<tr key={id}>
<td>{nickname || id}</td>
<td>
<button type="button" class="btn variant-filled" on:click={() => handleRemoveKey(id)} color="red">
<Settings />
</button>
</td>
</tr>
))}
</tbody> -->
</table>
<form class="space-y-4" on:submit|preventDefault={handleSubmit}>
<input
bind:value={email}
placeholder='email'
class="block w-full p-3 border rounded-md border-slate-300 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
/>
<button type="submit" class="btn variant-filled">Add a new device</button>

</form>
</div>
</div>
</div>

8 changes: 6 additions & 2 deletions apps/console/src/routes/(app)/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ export let data;
<meta name="description" content="Account Settings" />
</svelte:head>

<h2 class="h2">Settings</h2>
<Debug {data} />
<div class="page-container">
<div class="page-section">
<h2 class="h2">Settings</h2>
<Debug {data} />
</div>
</div>
9 changes: 5 additions & 4 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ services:
# mailpit - smtp relay and UI
# NOTE: this mailpit use self-signed certs with SAN: mailpit,
# located in ./infra/base/mailpit/certs
# you may have to add its CA cert to hasura-auth system trust store
# e.g. ./infra/components/cacerts/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt
# you have to add its CA cert to `hasura-auth` system's trust store
# e.g. ./infra/base/mailpit/certs/ca.pem:/etc/ssl/certs/ca-certificates.crt
###########################################################################
mailpit:
image: axllent/mailpit:v1.18.4
Expand All @@ -153,8 +153,8 @@ services:
MP_SMTP_TLS_CERT: /certs/tls.crt
MP_SMTP_TLS_KEY: /certs/tls.key
# only enable below 3 lines, if you also want to send email copy via relay
MP_SMTP_RELAY_HOST: smtp.gmail.com
MP_SMTP_RELAY_PORT: 25
MP_SMTP_RELAY_HOST: smtp-relay.gmail.com
MP_SMTP_RELAY_PORT: 587
MP_SMTP_RELAY_MATCHING: "@chinthagunta\\.com$" # (or) MP_SMTP_RELAY_ALL: true
# MP_SMTP_RELAY_ALL: true
expose:
Expand Down Expand Up @@ -194,6 +194,7 @@ services:
user: 1000:1000
volumes:
- ./nhost/emails:/app/email-templates
- ./infra/base/mailpit/certs/ca.pem:/etc/ssl/certs/ca-certificates.crt
environment:
AUTH_LOG_LEVEL: info
AUTH_ACCESS_CONTROL_ALLOWED_EMAIL_DOMAINS: ${AUTH_ACCESS_CONTROL_ALLOWED_EMAIL_DOMAINS:-}
Expand Down
2 changes: 1 addition & 1 deletion infra/base/mailpit/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mailpit

SMTP Relay for Development time.
**SMTP Relay** for *Development* time.

## Mailpit TLS Certs

Expand Down

0 comments on commit 45930fb

Please sign in to comment.