Started login checks
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
export type IsOwnBackend = {
|
||||
builtWithBackend: boolean;
|
||||
internalAuth: boolean;
|
||||
requireAuth: boolean;
|
||||
};
|
||||
|
||||
export function isOwnBackend(): IsOwnBackend | null {
|
||||
if (import.meta.env.VITE_BUILD_WITH_BACKEND !== 'true') return null;
|
||||
|
||||
return {
|
||||
builtWithBackend: true,
|
||||
internalAuth: import.meta.env.VITE_INTERNAL_AUTH !== 'false',
|
||||
requireAuth: import.meta.env.VITE_REQUIRE_AUTH !== 'false'
|
||||
};
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import { page } from '$app/state';
|
||||
import { Capacitor } from '@capacitor/core';
|
||||
import { Share } from '@capacitor/share';
|
||||
import { Clipboard } from '@capacitor/clipboard';
|
||||
import { isOwnBackend } from './backend';
|
||||
|
||||
export function isMobile(): boolean {
|
||||
const userAgent = navigator.userAgent;
|
||||
@@ -230,23 +231,8 @@ export function findElementForTime<T>(
|
||||
return null;
|
||||
}
|
||||
|
||||
export type IsOwnBackend = {
|
||||
builtWithBackend: boolean;
|
||||
internalAuth: boolean;
|
||||
requireAuth: boolean;
|
||||
};
|
||||
export function isOwnBackend(): IsOwnBackend | false {
|
||||
if (import.meta.env.VITE_BUILD_WITH_BACKEND !== 'true') return false;
|
||||
|
||||
return {
|
||||
builtWithBackend: true,
|
||||
internalAuth: import.meta.env.VITE_INTERNAL_AUTH === 'false',
|
||||
requireAuth: import.meta.env.VITE_REQUIRE_AUTH === 'false'
|
||||
};
|
||||
}
|
||||
|
||||
export function isUnrestrictedPlatform(): boolean {
|
||||
return isOwnBackend() !== false || Capacitor.isNativePlatform();
|
||||
return isOwnBackend() !== null || Capacitor.isNativePlatform();
|
||||
}
|
||||
|
||||
export function isYTBackend(): boolean {
|
||||
|
||||
@@ -42,9 +42,12 @@
|
||||
import { isYTBackend, clearCaches, truncate } from '$lib/misc';
|
||||
import Author from '$lib/components/Author.svelte';
|
||||
import Toast from '$lib/components/Toast.svelte';
|
||||
import { isOwnBackend } from '$lib/backend';
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
const showLogin = !isYTBackend() || isOwnBackend()?.internalAuth;
|
||||
|
||||
let mobileSearchShow = $state(false);
|
||||
|
||||
let isLoggedIn = $state(false);
|
||||
@@ -112,6 +115,10 @@
|
||||
});
|
||||
|
||||
async function login() {
|
||||
if (isOwnBackend()?.internalAuth) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$isAndroidTvStore) {
|
||||
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
||||
const path = new URL(`${get(instanceStore)}/authorize_token`);
|
||||
@@ -281,7 +288,7 @@
|
||||
<i>settings</i>
|
||||
<div>{$_('layout.settings')}</div>
|
||||
</a>
|
||||
{#if !isYTBackend()}
|
||||
{#if showLogin}
|
||||
{#if !isLoggedIn}
|
||||
<a onclick={login} href="#login">
|
||||
<i>login</i>
|
||||
@@ -367,7 +374,7 @@
|
||||
<div class="tooltip bottom">{$_('layout.settings')}</div>
|
||||
</button>
|
||||
|
||||
{#if !isYTBackend()}
|
||||
{#if showLogin}
|
||||
{#if !isLoggedIn}
|
||||
<button onclick={login} class="circle large transparent">
|
||||
<i>login</i>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { isOwnBackend } from '$lib/backend';
|
||||
import psl from 'psl';
|
||||
|
||||
const allowedDomains: string[] = [
|
||||
@@ -26,6 +27,16 @@ dynamicAllowDomains.forEach((domain) => {
|
||||
});
|
||||
|
||||
async function proxyRequest(request: Request, urlToProxy: string): Promise<Response> {
|
||||
const backendRestrictions = isOwnBackend();
|
||||
if (!backendRestrictions) {
|
||||
// Shouldn't be possible.
|
||||
return new Response('How did you get here?', { status: 400 });
|
||||
}
|
||||
|
||||
if (backendRestrictions.requireAuth) {
|
||||
return new Response('Auth required', { status: 401 });
|
||||
}
|
||||
|
||||
let urlToProxyObj: URL;
|
||||
try {
|
||||
urlToProxyObj = new URL(decodeURIComponent(urlToProxy));
|
||||
|
||||
Reference in New Issue
Block a user