+page.svelte 4.52 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';
7
8
	import toast from 'svelte-french-toast';

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
{#if loaded}
61
62
63
	<div class="fixed m-10 z-50">
		<div class="flex space-x-2">
			<div class=" self-center">
64
				<img src="{WEBUI_BASE_URL}/static/favicon.png" class=" w-8 rounded-full" alt="logo" />
65
66
67
68
69
			</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
70
		<!-- <div class="hidden lg:flex lg:flex-1 px-10 md:px-16 w-full bg-yellow-50 justify-center">
71
72
73
74
75
76
77
78
79
80
81
			<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
82
		</div> -->
83

Timothy J. Baek's avatar
Timothy J. Baek committed
84
		<div class="w-full max-w-lg px-10 md:px-16 bg-white min-h-screen flex flex-col">
85
86
87
88
			<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
89
						submitHandler();
90
91
					}}
				>
Timothy J. Baek's avatar
Timothy J. Baek committed
92
					<div class=" text-xl md:text-2xl font-bold">
93
						{mode === 'signin' ? 'Sign in' : 'Sign up'} to {$WEBUI_NAME}
94
95
					</div>

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

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

							<hr class=" my-3" />
118
119
						{/if}

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

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

Timothy J. Baek's avatar
Timothy J. Baek committed
145
					<div class="mt-5">
146
						<button
Timothy J. Baek's avatar
Timothy J. Baek committed
147
							class=" bg-gray-900 hover:bg-gray-800 w-full rounded-full text-white font-semibold text-sm py-3 transition"
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
							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
176
177
178
179
180
181

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