fixed callback url

This commit is contained in:
ari melody 2024-06-29 19:52:52 +01:00
parent 509a817065
commit 71a95c92db
Signed by: ari
GPG key ID: CF99829C92678188
7 changed files with 32 additions and 22 deletions

View file

@ -8,7 +8,7 @@ import { get } from 'svelte/store';
export async function createApp(host) { export async function createApp(host) {
let form = new FormData(); let form = new FormData();
form.append("client_name", "space social"); form.append("client_name", "space social");
form.append("redirect_uris", `${location.origin}`); form.append("redirect_uris", `${location.origin}/callback`);
form.append("scopes", "read write push"); form.append("scopes", "read write push");
form.append("website", "https://spacesocial.arimelody.me"); form.append("website", "https://spacesocial.arimelody.me");
@ -35,7 +35,7 @@ export function getOAuthUrl() {
return `https://${client.instance.host}/oauth/authorize` + return `https://${client.instance.host}/oauth/authorize` +
`?client_id=${client.app.id}` + `?client_id=${client.app.id}` +
"&scope=read+write+push" + "&scope=read+write+push" +
`&redirect_uri=${location.origin}` + `&redirect_uri=${location.origin}/callback` +
"&response_type=code"; "&response_type=code";
} }
@ -44,7 +44,7 @@ export async function getToken(code) {
let form = new FormData(); let form = new FormData();
form.append("client_id", client.app.id); form.append("client_id", client.app.id);
form.append("client_secret", client.app.secret); form.append("client_secret", client.app.secret);
form.append("redirect_uri", `${location.origin}`); form.append("redirect_uri", `${location.origin}/callback`);
form.append("grant_type", "authorization_code"); form.append("grant_type", "authorization_code");
form.append("code", code); form.append("code", code);
form.append("scope", "read write push"); form.append("scope", "read write push");

View file

@ -1,4 +1,7 @@
<script> <script>
import '$lib/app.css';
import LogoLight from '$lib/../img/spacesocial-logo-light.svg';
import LogoDark from '$lib/../img/spacesocial-logo-dark.svg';
import Navigation from '$lib/ui/Navigation.svelte'; import Navigation from '$lib/ui/Navigation.svelte';
import Widgets from '$lib/ui/Widgets.svelte'; import Widgets from '$lib/ui/Widgets.svelte';
</script> </script>

View file

@ -1,9 +1,4 @@
<script> <script>
import '$lib/app.css';
import LogoLight from '$lib/../img/spacesocial-logo-light.svg';
import LogoDark from '$lib/../img/spacesocial-logo-dark.svg';
import Navigation from '$lib/ui/Navigation.svelte';
import Widgets from '$lib/ui/Widgets.svelte';
import Feed from '$lib/ui/Feed.svelte'; import Feed from '$lib/ui/Feed.svelte';
import { Client } from '$lib/client/client.js'; import { Client } from '$lib/client/client.js';
import Button from '$lib/ui/Button.svelte'; import Button from '$lib/ui/Button.svelte';
@ -14,16 +9,6 @@
let instance_url_error = false; let instance_url_error = false;
let logging_in = false; let logging_in = false;
if (typeof location !== typeof undefined) {
let auth_code = new URLSearchParams(location.search).get("code");
if (auth_code) {
client.getToken(auth_code).then(() => {
client.save();
location = location.origin;
});
}
}
if (client.app && client.app.token) { if (client.app && client.app.token) {
// this triggers the client actually getting the authenticated user's data. // this triggers the client actually getting the authenticated user's data.
client.verifyCredentials().then(user => { client.verifyCredentials().then(user => {
@ -97,8 +82,8 @@
<h1>Home</h1> <h1>Home</h1>
<nav> <nav>
<Button centered active>Home</Button> <Button centered active>Home</Button>
<Button centered disabled>Local</Button> <Button centered disabled>Local</Button>
<Button centered disabled>Federated</Button> <Button centered disabled>Federated</Button>
</nav> </nav>
</header> </header>
@ -112,6 +97,7 @@
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
text-align: center;
} }
a { a {

View file

@ -0,0 +1 @@
<slot/>

View file

@ -0,0 +1,20 @@
import { Client } from '$lib/client/client.js';
import { goto } from '$app/navigation';
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';
export const ssr = false;
export async function load({ params, url }) {
const client = get(Client.get());
let auth_code = url.searchParams.get("code");
if (auth_code) {
client.getToken(auth_code).then(() => {
client.save();
goto(url.origin);
});
}
error(400, {
message: "Bad request"
});
}

View file

View file

@ -11,8 +11,8 @@ const config = {
adapter: adapter({ adapter: adapter({
pages: 'build', pages: 'build',
assets: 'build', assets: 'build',
fallback: undefined, fallback: "index.html",
precompress: false, precompress: true,
strict: true, strict: true,
}), }),
version: { version: {