rough tauri auth (#167)
This commit is contained in:
10
src/Auth.tsx
10
src/Auth.tsx
@ -2,12 +2,22 @@ import useSWR from 'swr'
|
||||
import fetcher from './lib/fetcher'
|
||||
import withBaseUrl from './lib/withBaseURL'
|
||||
import { App } from './App'
|
||||
import { SetToken } from './components/TokenInput'
|
||||
import { useStore } from './useStore'
|
||||
|
||||
export const Auth = () => {
|
||||
const { data: user } = useSWR(withBaseUrl('/user'), fetcher) as any
|
||||
const {token} = useStore((s) => ({
|
||||
token: s.token
|
||||
}))
|
||||
|
||||
const isLocalHost =
|
||||
typeof window !== 'undefined' && window.location.hostname === 'localhost'
|
||||
|
||||
if ((window as any).__TAURI__ && !token) {
|
||||
return <SetToken />
|
||||
}
|
||||
|
||||
if (!user && !isLocalHost) {
|
||||
return (
|
||||
<>
|
||||
|
Reference in New Issue
Block a user