access token endpoints and other backend support

This commit is contained in:
Milo Schwartz
2024-12-18 23:14:26 -05:00
parent 283fb3990c
commit 72dc02ff2e
22 changed files with 905 additions and 107 deletions

View File

@@ -45,7 +45,7 @@ import { Alert, AlertDescription } from "@app/components/ui/alert";
import { formatAxiosError } from "@app/lib/utils";
import { AxiosResponse } from "axios";
import LoginForm from "@app/components/LoginForm";
import { AuthWithPasswordResponse, AuthWithWhitelistResponse } from "@server/routers/resource";
import { AuthWithPasswordResponse, AuthWithAccessTokenResponse } from "@server/routers/resource";
import { redirect } from "next/dist/server/api-utils";
import ResourceAccessDenied from "./ResourceAccessDenied";
import { createApiClient } from "@app/api";
@@ -166,7 +166,7 @@ export default function ResourceAuthPortal(props: ResourceAuthPortalProps) {
const onWhitelistSubmit = (values: any) => {
setLoadingLogin(true);
api.post<AxiosResponse<AuthWithWhitelistResponse>>(
api.post<AxiosResponse<AuthWithAccessTokenResponse>>(
`/auth/resource/${props.resource.id}/whitelist`,
{ email: values.email, otp: values.otp }
)

View File

@@ -43,8 +43,8 @@ export default async function ResourceAuthPage(props: {
);
}
const hasAuth = authInfo.password || authInfo.pincode || authInfo.sso;
const isSSOOnly = authInfo.sso && !authInfo.password && !authInfo.pincode;
const hasAuth = authInfo.password || authInfo.pincode || authInfo.sso || authInfo.whitelist;
const isSSOOnly = authInfo.sso && !authInfo.password && !authInfo.pincode && !authInfo.whitelist;
const redirectUrl = searchParams.redirect || authInfo.url;
@@ -70,8 +70,6 @@ export default async function ResourceAuthPage(props: {
AxiosResponse<CheckResourceSessionResponse>
>(`/resource-session/${params.resourceId}/${sessionId}`);
console.log("resource session already exists and is valid");
if (res && res.data.data.valid) {
doRedirect = true;
}
@@ -96,7 +94,6 @@ export default async function ResourceAuthPage(props: {
await authCookieHeader(),
);
console.log(res.data);
doRedirect = true;
} catch (e) {
userIsUnauthorized = true;