mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-10 04:22:13 +10:00
feat(auth): offer manual signin
This commit is contained in:
@ -42,6 +42,31 @@
|
|||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<div class="mt-5" v-if="offerManual">
|
||||||
|
<h1 class="text-zinc-100 font-semibold">Having trouble?</h1>
|
||||||
|
<p class="mt-1 text-zinc-400 text-sm">
|
||||||
|
You can manually enter the token from your web browser.
|
||||||
|
</p>
|
||||||
|
<div class="inline-flex gap-x-1 mt-2 w-full">
|
||||||
|
<input
|
||||||
|
id="token"
|
||||||
|
name="token"
|
||||||
|
type="text"
|
||||||
|
autocomplete="token"
|
||||||
|
required
|
||||||
|
class="grow block w-full rounded-md border-0 py-1.5 px-3 shadow-sm bg-zinc-950/20 text-zinc-300 ring-1 ring-inset ring-zinc-800 placeholder:text-zinc-400 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6"
|
||||||
|
v-model="manualToken"
|
||||||
|
/>
|
||||||
|
<LoadingButton
|
||||||
|
:loading="manualLoading"
|
||||||
|
@click="() => continueManual_wrapper()"
|
||||||
|
class="w-fit"
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</LoadingButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="error" class="mt-5 rounded-md bg-red-600/10 p-4">
|
<div v-if="error" class="mt-5 rounded-md bg-red-600/10 p-4">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="flex-shrink-0">
|
<div class="flex-shrink-0">
|
||||||
@ -101,6 +126,10 @@ import { invoke } from "@tauri-apps/api/core";
|
|||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const error = ref<string | undefined>();
|
const error = ref<string | undefined>();
|
||||||
|
|
||||||
|
const offerManual = ref(false);
|
||||||
|
const manualToken = ref("");
|
||||||
|
const manualLoading = ref(false);
|
||||||
|
|
||||||
async function auth() {
|
async function auth() {
|
||||||
await invoke("auth_initiate");
|
await invoke("auth_initiate");
|
||||||
}
|
}
|
||||||
@ -111,5 +140,23 @@ function authWrapper_wrapper() {
|
|||||||
loading.value = false;
|
loading.value = false;
|
||||||
error.value = e;
|
error.value = e;
|
||||||
});
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
offerManual.value = true;
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function continueManual() {
|
||||||
|
await invoke("manual_recieve_handshake", { token: manualToken.value });
|
||||||
|
}
|
||||||
|
|
||||||
|
function continueManual_wrapper() {
|
||||||
|
loading.value = true;
|
||||||
|
continueManual()
|
||||||
|
.catch((e) => {
|
||||||
|
error.value = e;
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
use std::{
|
use std::{env, sync::Mutex};
|
||||||
env,
|
|
||||||
sync::Mutex,
|
|
||||||
};
|
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
@ -138,6 +135,12 @@ fn recieve_handshake_logic(app: &AppHandle, path: String) -> Result<(), RemoteAc
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn manual_recieve_handshake(app: AppHandle, token: String) -> Result<(), String> {
|
||||||
|
recieve_handshake(app, format!("handshake/{}", token));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn recieve_handshake(app: AppHandle, path: String) {
|
pub fn recieve_handshake(app: AppHandle, path: String) {
|
||||||
// Tell the app we're processing
|
// Tell the app we're processing
|
||||||
app.emit("auth/processing", ()).unwrap();
|
app.emit("auth/processing", ()).unwrap();
|
||||||
|
|||||||
@ -11,7 +11,7 @@ mod state;
|
|||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use crate::db::DatabaseImpls;
|
use crate::db::DatabaseImpls;
|
||||||
use auth::{auth_initiate, generate_authorization_header, recieve_handshake, retry_connect};
|
use auth::{auth_initiate, generate_authorization_header, manual_recieve_handshake, recieve_handshake, retry_connect};
|
||||||
use cleanup::{cleanup_and_exit, quit};
|
use cleanup::{cleanup_and_exit, quit};
|
||||||
use db::{
|
use db::{
|
||||||
add_download_dir, delete_download_dir, fetch_download_dir_stats, DatabaseInterface, GameStatus,
|
add_download_dir, delete_download_dir, fetch_download_dir_stats, DatabaseInterface, GameStatus,
|
||||||
@ -213,6 +213,7 @@ pub fn run() {
|
|||||||
// Auth
|
// Auth
|
||||||
auth_initiate,
|
auth_initiate,
|
||||||
retry_connect,
|
retry_connect,
|
||||||
|
manual_recieve_handshake,
|
||||||
// Remote
|
// Remote
|
||||||
use_remote,
|
use_remote,
|
||||||
gen_drop_url,
|
gen_drop_url,
|
||||||
@ -269,6 +270,7 @@ pub fn run() {
|
|||||||
info!("handling drop:// url");
|
info!("handling drop:// url");
|
||||||
let binding = event.urls();
|
let binding = event.urls();
|
||||||
let url = binding.first().unwrap();
|
let url = binding.first().unwrap();
|
||||||
|
return; // We're macOS
|
||||||
if url.host_str().unwrap() == "handshake" {
|
if url.host_str().unwrap() == "handshake" {
|
||||||
recieve_handshake(handle.clone(), url.path().to_string())
|
recieve_handshake(handle.clone(), url.path().to_string())
|
||||||
}
|
}
|
||||||
@ -345,16 +347,20 @@ pub fn run() {
|
|||||||
|
|
||||||
responder.respond(resp);
|
responder.respond(resp);
|
||||||
})
|
})
|
||||||
.on_window_event(|window, event| if let WindowEvent::CloseRequested { api, .. } = event {
|
.on_window_event(|window, event| {
|
||||||
window.hide().unwrap();
|
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||||
api.prevent_close();
|
window.hide().unwrap();
|
||||||
|
api.prevent_close();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|
||||||
app.run(|app_handle, event| if let RunEvent::ExitRequested { code, api, .. } = event {
|
app.run(|app_handle, event| {
|
||||||
if code.is_none() {
|
if let RunEvent::ExitRequested { code, api, .. } = event {
|
||||||
api.prevent_exit();
|
if code.is_none() {
|
||||||
|
api.prevent_exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user