-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script> | ||
import { TextInput, Button } from '@svelteuidev/core'; | ||
import { Header } from '$lib'; | ||
let email = ''; | ||
let password = ''; | ||
let accessToken = ''; | ||
async function handleSubmit() { | ||
try { | ||
const formData = new FormData(); | ||
formData.append('username', email); | ||
formData.append('password', password); | ||
const response = await fetch('http://localhost:8002/auth/login/', { | ||
method: 'POST', | ||
body: formData | ||
}); | ||
if (response.ok) { | ||
const data = await response.json(); | ||
accessToken = data.access_token; | ||
// Save the token to localStorage or sessionStorage | ||
localStorage.setItem('accessToken', accessToken); | ||
window.location.href = '/'; | ||
} else { | ||
alert('Login failed. Please check your credentials.'); | ||
} | ||
} catch (error) { | ||
console.error('Error logging in:', error); | ||
alert('An error occurred while logging in. Please try again later.'); | ||
} | ||
} | ||
</script> | ||
|
||
<Header/> | ||
|
||
<div style="width: 300px; margin: auto; top: 50%; transform: translate(0, 30vh); border: 1px solid gray; padding:10px; border-radius:5px"> | ||
<TextInput label='Email' bind:value={email} /> | ||
<TextInput type='password' label='Password' bind:value={password} /> | ||
<br/> | ||
<Button on:click={handleSubmit}>Login</Button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters