import { Alert, Input, Space, Spin, Collapse, Typography } from 'antd'; import React, { FC, useState } from 'react'; import isValidURL from '../../../utils/urls'; const { Panel } = Collapse; const { Link } = Typography; export type IndieAuthModalProps = { authenticated: boolean; displayName: string; accessToken: string; }; export const IndieAuthModal: FC = ({ authenticated, displayName: username, accessToken, }) => { const [errorMessage, setErrorMessage] = useState(null); const [loading, setLoading] = useState(false); const [valid, setValid] = useState(false); const [host, setHost] = useState(''); const message = !authenticated ? ( Use your own domain to authenticate {username} or login as a previously{' '} authenticated chat user using IndieAuth. ) : ( You are already authenticated. However, you can add other domains or log in as a different user. ); let errorMessageText = errorMessage; if (errorMessageText) { if (errorMessageText.includes('url does not support indieauth')) { errorMessageText = 'The provided URL is either invalid or does not support IndieAuth.'; } } const validate = (url: string) => { if (!isValidURL(url)) { setValid(false); return; } if (!url.includes('.')) { setValid(false); return; } setValid(true); }; const onInput = (e: React.ChangeEvent) => { // Don't allow people to type custom ports or protocols. const char = (e.nativeEvent as any).data; if (char === ':') { return; } setHost(e.target.value); const h = `https://${e.target.value}`; validate(h); }; const submitButtonPressed = async () => { if (!valid) { return; } setLoading(true); try { const url = `/api/auth/indieauth?accessToken=${accessToken}`; const h = `https://${host}`; const data = { authHost: h }; const rawResponse = await fetch(url, { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify(data), }); const content = await rawResponse.json(); if (content.message) { setErrorMessage(content.message); setLoading(false); return; } if (!content.redirect) { setErrorMessage('Auth provider did not return a redirect URL.'); setLoading(false); return; } if (content.redirect) { const { redirect } = content; window.location = redirect; } } catch (e) { setErrorMessage(e.message); } setLoading(false); }; return ( {message} {errorMessageText && ( )}
Your domain
0 ? 'error' : undefined} onSearch={submitButtonPressed} />

IndieAuth allows for a completely independent and decentralized way of identifying yourself using your own domain.

If you run an Owncast instance, you can use that domain here. Otherwise,{' '} learn more about how you can support IndieAuth .

Note: This is for authentication purposes only, and no personal information will be accessed or stored.
); };