mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 17:59:28 +08:00
possible fix for ios safari auth popup blockage
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog'
|
} from '@/components/ui/dialog'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { AuthMethodsList } from 'pocketbase'
|
import { AuthMethodsList, OAuth2AuthConfig } from 'pocketbase'
|
||||||
import { Link } from '../router'
|
import { Link } from '../router'
|
||||||
|
|
||||||
const honeypot = v.literal('')
|
const honeypot = v.literal('')
|
||||||
@@ -64,7 +64,7 @@ export function UserAuthForm({
|
|||||||
authMethods: AuthMethodsList
|
authMethods: AuthMethodsList
|
||||||
}) {
|
}) {
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false)
|
const [isLoading, setIsLoading] = useState<boolean>(false)
|
||||||
const [isGitHubLoading, setIsOauthLoading] = useState<boolean>(false)
|
const [isOauthLoading, setIsOauthLoading] = useState<boolean>(false)
|
||||||
const [errors, setErrors] = useState<Record<string, string | undefined>>({})
|
const [errors, setErrors] = useState<Record<string, string | undefined>>({})
|
||||||
|
|
||||||
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
||||||
@@ -145,7 +145,7 @@ export function UserAuthForm({
|
|||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
autoComplete="username"
|
autoComplete="username"
|
||||||
autoCorrect="off"
|
autoCorrect="off"
|
||||||
disabled={isLoading || isGitHubLoading}
|
disabled={isLoading || isOauthLoading}
|
||||||
className="pl-9"
|
className="pl-9"
|
||||||
/>
|
/>
|
||||||
{errors?.username && (
|
{errors?.username && (
|
||||||
@@ -167,7 +167,7 @@ export function UserAuthForm({
|
|||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
autoCorrect="off"
|
autoCorrect="off"
|
||||||
disabled={isLoading || isGitHubLoading}
|
disabled={isLoading || isOauthLoading}
|
||||||
className="pl-9"
|
className="pl-9"
|
||||||
/>
|
/>
|
||||||
{errors?.email && <p className="px-1 text-xs text-red-600">{errors.email}</p>}
|
{errors?.email && <p className="px-1 text-xs text-red-600">{errors.email}</p>}
|
||||||
@@ -184,7 +184,7 @@ export function UserAuthForm({
|
|||||||
required
|
required
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
disabled={isLoading || isGitHubLoading}
|
disabled={isLoading || isOauthLoading}
|
||||||
className="pl-9"
|
className="pl-9"
|
||||||
/>
|
/>
|
||||||
{errors?.password && <p className="px-1 text-xs text-red-600">{errors.password}</p>}
|
{errors?.password && <p className="px-1 text-xs text-red-600">{errors.password}</p>}
|
||||||
@@ -202,7 +202,7 @@ export function UserAuthForm({
|
|||||||
required
|
required
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
disabled={isLoading || isGitHubLoading}
|
disabled={isLoading || isOauthLoading}
|
||||||
className="pl-9"
|
className="pl-9"
|
||||||
/>
|
/>
|
||||||
{errors?.passwordConfirm && (
|
{errors?.passwordConfirm && (
|
||||||
@@ -246,20 +246,40 @@ export function UserAuthForm({
|
|||||||
'justify-self-center': !authMethods.emailPassword,
|
'justify-self-center': !authMethods.emailPassword,
|
||||||
'px-5': !authMethods.emailPassword,
|
'px-5': !authMethods.emailPassword,
|
||||||
})}
|
})}
|
||||||
onClick={async () => {
|
onClick={() => {
|
||||||
setIsOauthLoading(true)
|
setIsOauthLoading(true)
|
||||||
try {
|
const oAuthOpts: OAuth2AuthConfig = {
|
||||||
await pb.collection('users').authWithOAuth2({ provider: provider.name })
|
provider: provider.name,
|
||||||
$authenticated.set(pb.authStore.isValid)
|
|
||||||
} catch (e) {
|
|
||||||
showLoginFaliedToast()
|
|
||||||
} finally {
|
|
||||||
setIsOauthLoading(false)
|
|
||||||
}
|
}
|
||||||
|
// https://github.com/pocketbase/pocketbase/discussions/2429#discussioncomment-5943061
|
||||||
|
if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) {
|
||||||
|
const authWindow = window.open()
|
||||||
|
if (!authWindow) {
|
||||||
|
setIsOauthLoading(false)
|
||||||
|
toast({
|
||||||
|
title: 'Error',
|
||||||
|
description: 'Please enable pop-ups for this site',
|
||||||
|
variant: 'destructive',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
oAuthOpts.urlCallback = (url) => {
|
||||||
|
authWindow.location.href = url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pb.collection('users')
|
||||||
|
.authWithOAuth2(oAuthOpts)
|
||||||
|
.then(() => {
|
||||||
|
$authenticated.set(pb.authStore.isValid)
|
||||||
|
})
|
||||||
|
.catch(showLoginFaliedToast)
|
||||||
|
.finally(() => {
|
||||||
|
setIsOauthLoading(false)
|
||||||
|
})
|
||||||
}}
|
}}
|
||||||
disabled={isLoading || isGitHubLoading}
|
disabled={isLoading || isOauthLoading}
|
||||||
>
|
>
|
||||||
{isGitHubLoading ? (
|
{isOauthLoading ? (
|
||||||
<LoaderCircle className="mr-2 h-4 w-4 animate-spin" />
|
<LoaderCircle className="mr-2 h-4 w-4 animate-spin" />
|
||||||
) : (
|
) : (
|
||||||
<img
|
<img
|
||||||
|
Reference in New Issue
Block a user