Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,25 @@
/**
* Handle initial load.
*/
const acceptedRoutes = ['/login', '/register', '/recover', '/invite'];
if ($user) {
if (!$page.url.pathname.startsWith('/console')) {
await goto(`${base}/console`, {
replaceState: true
});
}
} else {
if (acceptedRoutes.includes($page.url.pathname)) {
await goto(`${base}${$page.url.pathname}${$page.url.search}`);
if (!$page.url.pathname.startsWith('/auth')) {
const acceptedRoutes = ['/login', '/register', '/recover', '/invite'];
if ($user) {
if (!$page.url.pathname.startsWith('/console')) {
await goto(`${base}/console`, {
replaceState: true
});
}
} else {
await goto(`${base}/login`, {
replaceState: true
});
if (acceptedRoutes.includes($page.url.pathname)) {
await goto(`${base}${$page.url.pathname}${$page.url.search}`);
} else {
await goto(`${base}/login`, {
replaceState: true
});
}
}
loading.set(false);
}
loading.set(false);
});

afterNavigate((navigation) => {
Expand Down
3 changes: 3 additions & 0 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import type { LayoutLoad } from './$types';
export const ssr = false;

export const load: LayoutLoad = async ({ depends, url }) => {
if (url.pathname.startsWith('/auth')) {
return;
}
depends(Dependencies.ACCOUNT);
try {
const account = await sdkForConsole.account.get();
Expand Down
7 changes: 7 additions & 0 deletions src/routes/auth/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import { Container } from '$lib/layout';
</script>

<Container>
<slot />
</Container>
29 changes: 29 additions & 0 deletions src/routes/auth/magic-url/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { Heading } from '$lib/components';
import { Account, Client } from '@aw-labs/appwrite-console';
import { onMount } from 'svelte';

const client = new Client();
const account = new Account(client);

onMount(async () => {
const projectId = $page.url.searchParams.get('project');
client.setEndpoint(`${$page.url.origin}/v1`).setProject(projectId);

const userId = $page.url.searchParams.get('userId');
const secret = $page.url.searchParams.get('secret');

await account.updateMagicURLSession(userId, secret);
await goto(`appwrite-callback-${projectId}://${$page.url.search}`);
});
</script>

<Heading tag="h1" size="1">Missing Redirect URL</Heading>
<p>
Your Magic URL login flow is missing a proper redirect URL. Please check the
<a href="https://appwrite.io/docs/client/account?sdk=web#createMagicURLSession"
>Magic URL docs</a>
and send request for new session with a valid redirect URL.
</p>
21 changes: 21 additions & 0 deletions src/routes/auth/oauth/failure/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { Heading } from '$lib/components';
import { onMount } from 'svelte';

onMount(async () => {
const project = $page.url.searchParams.get('project');
if (project) {
await goto(`appwrite-callback-${project}://${$page.url.search}`);
}
});
</script>

<Heading tag="h1" size="1">Missing Redirect URL</Heading>
<p class="text">
Your OAuth login flow is missing a proper redirect URL. Please check the
<a class="link" href="https://appwrite.io/docs/client/account?sdk=web#createOAuth2Session"
>OAuth docs</a>
and send request for new session with a valid callback URL.
</p>
21 changes: 21 additions & 0 deletions src/routes/auth/oauth/success/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { Heading } from '$lib/components';
import { onMount } from 'svelte';

onMount(async () => {
const project = $page.url.searchParams.get('project');
if (project) {
await goto(`appwrite-callback-${project}://${$page.url.search}`);
}
});
</script>

<Heading tag="h1" size="1">Missing Redirect URL</Heading>
<p class="text">
Your OAuth login flow is missing a proper redirect URL. Please check the
<a class="link" href="https://appwrite.io/docs/client/account?sdk=web#createOAuth2Session"
>OAuth docs</a>
and send request for new session with a valid callback URL.
</p>