7b862b9438
* Delete the proxy app (was v2) * Delete RunPresenterElectric * Select the best proj/org/env * Storing current proj/env in DB. Initial selection logic working with tasks page * 2sm needed to be in the Tailwind merge list * Move the task stream route (although we don’t actually use the env for now) * Alerts moved from /v3 * API keys page moved from /v3 * Concurrency page moved from /v3 * WIP on side menu sections * Improved the accordion animation * Moved schedules from /v3 * More pages moved * Move pages working * Run page working * Schedules working * Moved deployments * Alert pages moved * Delete electric hooks, not used * Started setting up blank states * Test page working * Removed “Select task” from the test page * Some work on deployment page * Style tweaks * Redirect from project root to approriate env * Improved env selector styling * Fix for jsx errors * Better min width on env selector * Improved the env switching logic * Added deployments to env routing * Redirect deployments to the correct env * Redirect run from proj to env * JSX icon fix * Only allow single env schedules from now on * Remove env var count from the API keys page * Move improvements and redirects * Project settings moved * Fix for scroll area on test page * Tweaked the test design * Made recent payloads column narrower * Improved the test layout some more * Added org icon, new project selector menu * WIP on org switching menu * Org switching is working * New menu working well, removed old side menu items * Buttons can now have a component name or an actual component for their icons * Removed the Projects page, instead redirect appropriately * Fix for broken blank states * Minor run table improvements * Removed unused switcher log and logic * Concurrency page fix for invalid html, improved layout * Minor improvements * Moved the side menu to the project level * Improved account styling * Moved org settings pages (with redirects) * Add current plan to billing side menu link * Upgrade to get staging from env dropdown * New env badge on concurrency limits page * Show Run Engine version in span presenter * New promote icon * Concurrency limits page is the sum of engine v1 + v2 queues * Fix for missing batch import * Added currentConcurrencyOfEnvQueue function * Basic avatar setting working * Avatar setting is working * You can change the color of your icon * Avatar improvements * Bugfix for mising prop * Removed some old env badges * Fixed replaying * Removed EnvironmentLabel * Old env badge deleted, changed everywhere to the new one * Fix for Slack integration paths * Fix for waitpoint completion form moving * Bulk replay/cancel env fix * Fix for alert webhook path * Redirect projects/v3/* to project/* * Fixes for CLI redirect routes * Remove welcome email (unused) * Change how we count schedules towards your limits * Use new schedules limits when checking a schedule * Added projectId back in to task queries (indexes) * WIP dev presence * CLI modal * Moved things around and use Context * Fix for p inside p * Dev connected status on run page * Correct dev env (not a teammates) * Show disconnected message at the end * Minor tweak on project dropdown icon padding * Fix for inconsistent date format for presence * Added a message when pushing to the billing page * Center the team page * Project settings page centered * Improvements to the dev presence
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { redirect } from "@remix-run/node";
|
|
import { getUserById } from "~/models/user.server";
|
|
import { authenticator } from "./auth.server";
|
|
import { getImpersonationId } from "./impersonation.server";
|
|
|
|
export async function getUserId(request: Request): Promise<string | undefined> {
|
|
const impersonatedUserId = await getImpersonationId(request);
|
|
|
|
if (impersonatedUserId) return impersonatedUserId;
|
|
|
|
let authUser = await authenticator.isAuthenticated(request);
|
|
return authUser?.userId;
|
|
}
|
|
|
|
export async function getUser(request: Request) {
|
|
const userId = await getUserId(request);
|
|
if (userId === undefined) return null;
|
|
|
|
const user = await getUserById(userId);
|
|
if (user) return user;
|
|
|
|
throw await logout(request);
|
|
}
|
|
|
|
export async function requireUserId(request: Request, redirectTo?: string) {
|
|
const userId = await getUserId(request);
|
|
if (!userId) {
|
|
const url = new URL(request.url);
|
|
const searchParams = new URLSearchParams([
|
|
["redirectTo", redirectTo ?? `${url.pathname}${url.search}`],
|
|
]);
|
|
throw redirect(`/login?${searchParams}`);
|
|
}
|
|
return userId;
|
|
}
|
|
|
|
export type UserFromSession = Awaited<ReturnType<typeof requireUser>>;
|
|
|
|
export async function requireUser(request: Request) {
|
|
const userId = await requireUserId(request);
|
|
|
|
const impersonationId = await getImpersonationId(request);
|
|
const user = await getUserById(userId);
|
|
if (user) {
|
|
return {
|
|
id: user.id,
|
|
email: user.email,
|
|
name: user.name,
|
|
displayName: user.displayName,
|
|
avatarUrl: user.avatarUrl,
|
|
admin: user.admin,
|
|
createdAt: user.createdAt,
|
|
updatedAt: user.updatedAt,
|
|
dashboardPreferences: user.dashboardPreferences,
|
|
confirmedBasicDetails: user.confirmedBasicDetails,
|
|
isImpersonating: !!impersonationId,
|
|
};
|
|
}
|
|
|
|
throw await logout(request);
|
|
}
|
|
|
|
export async function logout(request: Request) {
|
|
return redirect("/logout");
|
|
}
|