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) {
let form = new FormData();
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("website", "https://spacesocial.arimelody.me");
@ -35,7 +35,7 @@ export function getOAuthUrl() {
return `https://${client.instance.host}/oauth/authorize` +
`?client_id=${client.app.id}` +
"&scope=read+write+push" +
`&redirect_uri=${location.origin}` +
`&redirect_uri=${location.origin}/callback` +
"&response_type=code";
}
@ -44,7 +44,7 @@ export async function getToken(code) {
let form = new FormData();
form.append("client_id", client.app.id);
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("code", code);
form.append("scope", "read write push");

View file

@ -1,4 +1,7 @@
<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';
</script>

View file

@ -1,9 +1,4 @@
<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 { Client } from '$lib/client/client.js';
import Button from '$lib/ui/Button.svelte';
@ -14,16 +9,6 @@
let instance_url_error = 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) {
// this triggers the client actually getting the authenticated user's data.
client.verifyCredentials().then(user => {
@ -112,6 +97,7 @@
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
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({
pages: 'build',
assets: 'build',
fallback: undefined,
precompress: false,
fallback: "index.html",
precompress: true,
strict: true,
}),
version: {