Skip to content

Commit

Permalink
fix: User redirect issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Nov 4, 2024
1 parent e7b8dad commit 1e6f42e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/components/ui/user-auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,31 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
const [error, setError] = React.useState("")
const { login } = useLogin()

const getRedirectUri = () => {
const getRedirectUri = (toHome = false) => {
let redirectUri = (router.query.redirect || "/") as string
redirectUri = redirectUri
.replace("http://", "")
.replace("https://", "")
.replace("www.", "")

if (toHome) return "/"

return redirectUri
}

const onLogin = async (data: z.infer<typeof otpSchema>) => {
setIsLoading(true)

try {
if (!data.otp) await login(data.name, data.password, "", data.type)
else await login(data.name, data.password, data.otp, data.type)
let axiosReply
if (!data.otp) axiosReply = await login(data.name, data.password, "", data.type)
else axiosReply = await login(data.name, data.password, data.otp, data.type)

setError("")
setTimeout(() => {
router.push(getRedirectUri())
const user = axiosReply.data.user
const isNonRedirectable = !!(user.status === 0 && user.permissions.view.redirect)
router.push(getRedirectUri(isNonRedirectable))
}, 500)
} catch (e: any) {
if (!e.response) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function IndexPage() {
if (viewPermissions.redirect) {
redirectNow(viewPermissions.redirect)
}
}, [viewPermissions.redirect])
}, [viewPermissions])

const dashboardGridItems = useMemo(() => {
return viewPermissions.dashboard
Expand Down

0 comments on commit 1e6f42e

Please sign in to comment.