Skip to content

Commit 8249a1a

Browse files
committed
single svelte page + specify cookie domain
- requires local keratin client change from keratin/authn-js#59
1 parent a502e47 commit 8249a1a

File tree

5 files changed

+50
-51
lines changed

5 files changed

+50
-51
lines changed

.env.sample

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# authn config
22
AUTHN_URL=http://localhost
33
PORT=5000
4-
PUBLIC_PORT=5001
4+
PUBLIC_PORT=443
55
APP_DOMAINS=*
66
# these ports are inside networks
77
REDIS_URL=redis://redis:6380/1
88
DATABASE_URL=postgres://postgres:password@postgres:5435/authn?sslmode=disable
99
HTTP_AUTH_USERNAME=authn
1010
HTTP_AUTH_PASSWORD=authn
1111
# APP_PASSWORD_RESET_URL=
12-
SAME_SITE=none
12+
SAME_SITE=None
13+
FORCE_SSL=true
1314
SECRET_KEY_BASE=todo
1415
# APP_SIGNING_KEY=
1516

ui/public/build/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/public/build/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/src/App.svelte

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
<script>
33
import { onMount } from 'svelte';
44
import { getTodos, addTodo, updateTodo, deleteTodo } from './apiService';
5-
import Login from "./Login.svelte";
65
import * as authn from "keratin-authn";
76
87
let todos = [];
98
let task = '';
109
1110
authn.setHost("https://auth.todoauthn.com/");
12-
authn.setCookieStore("todo", {path: "/", sameSite: "None"});
11+
authn.setCookieStore("todo", {path: "/", sameSite: "None", domain: "todoauthn.com"});
1312
1413
onMount(async () => {
1514
await authn.importSession();
16-
todos = await getTodos();
15+
todos = await getTodos() ?? [];
1716
});
1817
1918
async function addNewTodo() {
@@ -32,9 +31,48 @@
3231
await deleteTodo(id);
3332
todos = todos.filter(todo => todo.id !== id);
3433
}
34+
35+
export let isRegistration = false; // Prop to specify whether it's a registration form
36+
37+
let email = '';
38+
let password = '';
39+
40+
async function handleSubmit() {
41+
if (isRegistration) {
42+
await authn.signup({username:email, password:password});
43+
} else {
44+
await authn.login({username: email, password:password});
45+
}
46+
window.location.reload();
47+
}
48+
49+
async function logout() {
50+
await authn.logout();
51+
window.location.reload();
52+
}
3553
</script>
54+
<!-- TODO: this is not updated after login until we refresh the page a couple times -->
3655
{#if authn.session() === ""}
37-
<Login />
56+
<div>
57+
<h2>{isRegistration ? 'Register' : 'Login'}</h2>
58+
<form>
59+
<label for="email">Email:</label>
60+
<input type="email" id="email" bind:value={email} />
61+
62+
<label for="password">Password:</label>
63+
<input type="password" id="password" bind:value={password} />
64+
65+
<button on:click={handleSubmit}>
66+
{isRegistration ? 'Register' : 'Login'}
67+
</button>
68+
69+
70+
<label>
71+
<input type="checkbox" bind:checked={isRegistration} />
72+
I'm new here
73+
</label>
74+
</form>
75+
</div>
3876
{:else}
3977
<main>
4078
<h1>TODO List</h1>
@@ -53,5 +91,8 @@
5391
</li>
5492
{/each}
5593
</ul>
94+
<div>
95+
<button on:click={logout}>Logout</button>
96+
</div>
5697
</main>
5798
{/if}

ui/src/Login.svelte

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)