-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: frontend bugs relating to redirects/tenants (#25)
* fix: frontend bugs - Adds a query param `tenant` to application routes - Allows setting an environment variable `SERVER_AUTH_SET_EMAIL_VERIFIED` to true which automatically sets the email to verified for new signups, since most local installations won't have an email verification mechanism - When a user is logged in, navigating to `/auth/login` or `/auth/register` will redirect to the application via the no-auth.tsx middleware - When there are no events found, the backend will no longer respond with a `500`-level error, and will return 0 rows instead
- Loading branch information
1 parent
e857004
commit ce61ead
Showing
20 changed files
with
285 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { redirect } from 'react-router-dom'; | ||
import api from '@/lib/api'; | ||
import queryClient from '@/query-client'; | ||
import { AxiosError, isAxiosError } from 'axios'; | ||
|
||
const noAuthMiddleware = async () => { | ||
try { | ||
const user = await queryClient.fetchQuery({ | ||
queryKey: ['user:get:current'], | ||
queryFn: async () => { | ||
const res = await api.userGetCurrent(); | ||
|
||
return res.data; | ||
}, | ||
}); | ||
|
||
if (user) { | ||
throw redirect('/'); | ||
} | ||
} catch (error) { | ||
if (error instanceof Response) { | ||
throw error; | ||
} else if (isAxiosError(error)) { | ||
const axiosErr = error as AxiosError; | ||
|
||
if (axiosErr.response?.status === 403) { | ||
return; | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export async function loader() { | ||
await noAuthMiddleware(); | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.