aboutsummaryrefslogtreecommitdiff
path: root/src/routes/user/+page.svelte
blob: e66c8503b9636bfb60f7e1799f12b3ce36a1fe0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script lang="ts">
	import { browser } from '$app/environment';
	import { goto } from '$app/navigation';
	import type { UserIdentity } from '$lib/Data/AniList/identity';
	import { onMount } from 'svelte';
	import { env } from '$env/dynamic/public';
	import HeadTitle from '$lib/Home/HeadTitle.svelte';
	import root from '$lib/Utility/root';

	const user =
		browser && localStorage.getItem('identity')
			? (JSON.parse(localStorage.getItem('identity') || '') as UserIdentity).name
			: null;

	onMount(() => {
		if (user) {
			goto(root(`/user/${user}`));
		} else {
			goto(
				`https://anilist.co/api/v2/oauth/authorize?client_id=${env.PUBLIC_ANILIST_CLIENT_ID}&redirect_uri=${env.PUBLIC_ANILIST_REDIRECT_URI}&response_type=code`
			);
		}
	});
</script>

<HeadTitle route="Profile" path="/user" />