Add login states & transition
This commit is contained in:
parent
466740675d
commit
37338232c2
@ -2,11 +2,13 @@ import { Route, HashRouter as Router } from "@solidjs/router";
|
|||||||
import type { Component } from "solid-js";
|
import type { Component } from "solid-js";
|
||||||
|
|
||||||
import { Login } from "./routes/Login";
|
import { Login } from "./routes/Login";
|
||||||
|
import { Home } from "./routes/Home";
|
||||||
|
|
||||||
const App: Component = () => (
|
const App: Component = () => (
|
||||||
<div>
|
<div>
|
||||||
<Router>
|
<Router>
|
||||||
<Route path="/" component={Login} />
|
<Route path="/" component={Login} />
|
||||||
|
<Route path="/home" component={Home} />
|
||||||
</Router>
|
</Router>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
15
frontend/src/routes/Home.tsx
Normal file
15
frontend/src/routes/Home.tsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { createSignal, onMount } from "solid-js";
|
||||||
|
|
||||||
|
export function Home() {
|
||||||
|
const [hidden, setHidden] = createSignal(true);
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
setTimeout(() => setHidden(false) , 150);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class={`min-h-screen ${hidden() ? "opacity-0" : "opacity-100"} transition-opacity`}>
|
||||||
|
Home :D
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@ -1,27 +1,36 @@
|
|||||||
import { createSignal } from "solid-js";
|
import { Show, createSignal } from "solid-js";
|
||||||
import { Login as GoLogin } from "../../wailsjs/go/main/App";
|
import { Login as GoLogin } from "../../wailsjs/go/main/App";
|
||||||
|
import { useNavigate } from "@solidjs/router";
|
||||||
|
|
||||||
export function Login() {
|
export function Login() {
|
||||||
const [loading, setLoading] = createSignal(false);
|
const [loading, setLoading] = createSignal(false);
|
||||||
|
const [error, setError] = createSignal("");
|
||||||
const [server, setServer] = createSignal("");
|
const [server, setServer] = createSignal("");
|
||||||
const [username, setUsername] = createSignal("");
|
const [username, setUsername] = createSignal("");
|
||||||
const [password, setPassword] = createSignal("");
|
const [password, setPassword] = createSignal("");
|
||||||
|
const [fade, setFade] = createSignal(false);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const login = async(ev: Event) => {
|
const login = async(ev: Event) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
setError("");
|
||||||
|
|
||||||
const success = await GoLogin(server(), username(), password());
|
GoLogin(server(), username(), password())
|
||||||
if (success) {
|
.then(() => {
|
||||||
alert(":D");
|
setFade(true);
|
||||||
} else {
|
setTimeout(() => {
|
||||||
alert("D:");
|
navigate("/home");
|
||||||
}
|
}, 150);
|
||||||
setLoading(false);
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
setError(err);
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="w-screen h-screen flex items-center justify-center">
|
<div class={`w-screen h-screen flex items-center justify-center ${fade() ? "opacity-0" : "opacity-100"} transition-opacity`}>
|
||||||
<div class="w-80">
|
<div class="w-80">
|
||||||
<form onSubmit={login} >
|
<form onSubmit={login} >
|
||||||
<h1 class="text-center font-black text-xl">Login</h1>
|
<h1 class="text-center font-black text-xl">Login</h1>
|
||||||
@ -65,6 +74,12 @@ export function Login() {
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<button type="submit" class="btn btn-primary">Login</button>
|
<button type="submit" class="btn btn-primary">Login</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Show when={error() !== ""}>
|
||||||
|
<div role="alert" class="alert alert-error">
|
||||||
|
<span class="text-white">Error: {error()}</span>
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
22
session.go
22
session.go
@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
@ -15,15 +15,15 @@ type AuthSuccess struct {
|
|||||||
SubsonicSalt string `json:"subsonicSalt"`
|
SubsonicSalt string `json:"subsonicSalt"`
|
||||||
SubsonicToken string `json:"subsonicToken"`
|
SubsonicToken string `json:"subsonicToken"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Username string `json:"fernando"`
|
Username string `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthError struct {
|
type AuthError struct {
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// / (Tries to) login to a remote navidrome server
|
// (Tries to) login to a remote navidrome server
|
||||||
func (a *App) Login(server, username, password string) bool {
|
func (a *App) Login(server, username, password string) (bool, error) {
|
||||||
client := resty.New()
|
client := resty.New()
|
||||||
|
|
||||||
// TODO: check server for leading https and ending /, normalize
|
// TODO: check server for leading https and ending /, normalize
|
||||||
@ -40,19 +40,17 @@ func (a *App) Login(server, username, password string) bool {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Login error", err)
|
log.Print("Login error", err)
|
||||||
return false
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.IsSuccess() {
|
if response.IsSuccess() {
|
||||||
log.Printf("%+v", successData)
|
log.Printf("%+v", successData)
|
||||||
return true
|
return true, nil
|
||||||
} else if response.IsError() {
|
} else if response.IsError() {
|
||||||
log.Printf("%+v", errorData)
|
log.Printf("%+v", errorData)
|
||||||
return false
|
return false, errors.New(errorData.Error + ".")
|
||||||
|
} else {
|
||||||
|
log.Printf("ehhh???")
|
||||||
|
return false, errors.New("invalid state")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print("Login: ", server, username, password)
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user