+page.svelte 4.59 KB
Newer Older
1
2
<script>
	import { goto } from '$app/navigation';
Timothy J. Baek's avatar
Timothy J. Baek committed
3
	import { userSignIn, userSignUp } from '$lib/apis/auths';
4
5
	import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
	import { WEBUI_NAME, config, user } from '$lib/stores';
Timothy J. Baek's avatar
Timothy J. Baek committed
6
	import { onMount } from 'svelte';
Jannik Streidl's avatar
Jannik Streidl committed
7
	import { toast } from 'svelte-sonner';
8

Timothy J. Baek's avatar
Timothy J. Baek committed
9
	let loaded = false;
10
11
12
13
14
15
	let mode = 'signin';

	let name = '';
	let email = '';
	let password = '';

Timothy J. Baek's avatar
Timothy J. Baek committed
16
17
18
	const setSessionUser = async (sessionUser) => {
		if (sessionUser) {
			console.log(sessionUser);
19
			toast.success(`You're now logged in.`);
Timothy J. Baek's avatar
Timothy J. Baek committed
20
21
			localStorage.token = sessionUser.token;
			await user.set(sessionUser);
22
23
24
25
			goto('/');
		}
	};

Timothy J. Baek's avatar
Timothy J. Baek committed
26
27
28
29
30
31
32
33
34
	const signInHandler = async () => {
		const sessionUser = await userSignIn(email, password).catch((error) => {
			toast.error(error);
			return null;
		});

		await setSessionUser(sessionUser);
	};

35
	const signUpHandler = async () => {
Timothy J. Baek's avatar
Timothy J. Baek committed
36
37
38
39
40
41
42
43
44
45
46
47
48
		const sessionUser = await userSignUp(name, email, password).catch((error) => {
			toast.error(error);
			return null;
		});

		await setSessionUser(sessionUser);
	};

	const submitHandler = async () => {
		if (mode === 'signin') {
			await signInHandler();
		} else {
			await signUpHandler();
49
50
51
		}
	};

Timothy J. Baek's avatar
Timothy J. Baek committed
52
	onMount(async () => {
Timothy J. Baek's avatar
Timothy J. Baek committed
53
		if ($user !== undefined) {
Timothy J. Baek's avatar
Timothy J. Baek committed
54
55
56
57
			await goto('/');
		}
		loaded = true;
	});
58
59
</script>

Timothy J. Baek's avatar
Timothy J. Baek committed
60
61
62
63
64
65
<svelte:head>
	<title>
		{`${$WEBUI_NAME}`}
	</title>
</svelte:head>

Timothy J. Baek's avatar
Timothy J. Baek committed
66
{#if loaded}
67
68
69
	<div class="fixed m-10 z-50">
		<div class="flex space-x-2">
			<div class=" self-center">
70
				<img src="{WEBUI_BASE_URL}/static/favicon.png" class=" w-8 rounded-full" alt="logo" />
71
72
73
74
75
			</div>
		</div>
	</div>

	<div class=" bg-white min-h-screen w-full flex justify-center font-mona">
Timothy J. Baek's avatar
Timothy J. Baek committed
76
		<!-- <div class="hidden lg:flex lg:flex-1 px-10 md:px-16 w-full bg-yellow-50 justify-center">
77
78
79
80
81
82
83
84
85
86
87
			<div class=" my-auto pb-16 text-left">
				<div>
					<div class=" font-bold text-yellow-600 text-4xl">
						Get up and running with <br />large language models, locally.
					</div>

					<div class="mt-2 text-yellow-600 text-xl">
						Run Llama 2, Code Llama, and other models. Customize and create your own.
					</div>
				</div>
			</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
88
		</div> -->
89

Timothy J. Baek's avatar
Timothy J. Baek committed
90
		<div class="w-full max-w-lg px-10 md:px-16 bg-white min-h-screen flex flex-col">
91
92
93
94
			<div class=" my-auto pb-10 w-full">
				<form
					class=" flex flex-col justify-center"
					on:submit|preventDefault={() => {
Timothy J. Baek's avatar
Timothy J. Baek committed
95
						submitHandler();
96
97
					}}
				>
Timothy J. Baek's avatar
Timothy J. Baek committed
98
					<div class=" text-xl md:text-2xl font-bold">
99
						{mode === 'signin' ? 'Sign in' : 'Sign up'} to {$WEBUI_NAME}
100
101
					</div>

102
103
					{#if mode === 'signup'}
						<div class=" mt-1 text-xs font-medium text-gray-500">
104
							ⓘ {$WEBUI_NAME} does not make any external connections, and your data stays securely on
Timothy J. Baek's avatar
Timothy J. Baek committed
105
							your locally hosted server.
106
107
108
						</div>
					{/if}

Timothy J. Baek's avatar
Timothy J. Baek committed
109
					<div class="flex flex-col mt-4">
110
111
						{#if mode === 'signup'}
							<div>
Timothy J. Baek's avatar
Timothy J. Baek committed
112
								<div class=" text-sm font-semibold text-left mb-1">Name</div>
113
114
115
								<input
									bind:value={name}
									type="text"
Timothy J. Baek's avatar
Timothy J. Baek committed
116
									class=" border px-4 py-2.5 rounded-2xl w-full text-sm"
117
									autocomplete="name"
Timothy J. Baek's avatar
Timothy J. Baek committed
118
									placeholder="Enter Your Full Name"
119
120
121
									required
								/>
							</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
122
123

							<hr class=" my-3" />
124
125
						{/if}

Timothy J. Baek's avatar
Timothy J. Baek committed
126
127
						<div class="mb-2">
							<div class=" text-sm font-semibold text-left mb-1">Email</div>
128
129
130
							<input
								bind:value={email}
								type="email"
Timothy J. Baek's avatar
Timothy J. Baek committed
131
								class=" border px-4 py-2.5 rounded-2xl w-full text-sm"
132
								autocomplete="email"
Timothy J. Baek's avatar
Timothy J. Baek committed
133
								placeholder="Enter Your Email"
134
135
136
137
138
								required
							/>
						</div>

						<div>
Timothy J. Baek's avatar
Timothy J. Baek committed
139
							<div class=" text-sm font-semibold text-left mb-1">Password</div>
140
141
142
							<input
								bind:value={password}
								type="password"
Timothy J. Baek's avatar
Timothy J. Baek committed
143
144
								class=" border px-4 py-2.5 rounded-2xl w-full text-sm"
								placeholder="Enter Your Password"
145
146
147
148
149
150
								autocomplete="current-password"
								required
							/>
						</div>
					</div>

Timothy J. Baek's avatar
Timothy J. Baek committed
151
					<div class="mt-5">
152
						<button
Timothy J. Baek's avatar
Timothy J. Baek committed
153
							class=" bg-gray-900 hover:bg-gray-800 w-full rounded-full text-white font-semibold text-sm py-3 transition"
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
							type="submit"
						>
							{mode === 'signin' ? 'Sign In' : 'Create Account'}
						</button>

						<div class=" mt-4 text-sm text-center">
							{mode === 'signin' ? `Don't have an account?` : `Already have an account?`}

							<button
								class=" font-medium underline"
								type="button"
								on:click={() => {
									if (mode === 'signin') {
										mode = 'signup';
									} else {
										mode = 'signin';
									}
								}}
							>
								{mode === 'signin' ? `Sign up` : `Sign In`}
							</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
{/if}
Timothy J. Baek's avatar
Timothy J. Baek committed
182
183
184
185
186
187

<style>
	.font-mona {
		font-family: 'Mona Sans';
	}
</style>