import { createFileRoute, redirect } from "@tanstack/react-router"

export const Route = createFileRoute("/_authed")({
	beforeLoad: ({ context }) => {
		if (context.error) {
			throw new Error("Not authenticated")
			// TODO: Redirect to login page
		}
	},
	errorComponent: ({ error }) => {
		if (error.message === "Not authenticated") {
			return (
				<p>
					Not authenticated. Please <a href="/login">login</a>.
				</p>
			)
		}
		throw error
	}
})
