Requested changes

This commit is contained in:
Daniel Hougaard
2024-09-10 11:07:25 +04:00
parent e6c0bbb25b
commit 54e6f4b607
4 changed files with 12 additions and 6 deletions
+2 -2
View File
@@ -43,7 +43,7 @@ export const registerLoginRouter = async (server: FastifyZodProvider) => {
schema: { schema: {
body: z.object({ body: z.object({
organizationId: z.string().trim(), organizationId: z.string().trim(),
customUserAgent: z.enum(["cli"]).optional() userAgent: z.enum(["cli"]).optional()
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -54,7 +54,7 @@ export const registerLoginRouter = async (server: FastifyZodProvider) => {
handler: async (req, res) => { handler: async (req, res) => {
const cfg = getConfig(); const cfg = getConfig();
const tokens = await server.services.login.selectOrganization({ const tokens = await server.services.login.selectOrganization({
userAgent: req.body.customUserAgent ?? req.headers["user-agent"], userAgent: req.body.userAgent ?? req.headers["user-agent"],
authJwtToken: req.headers.authorization, authJwtToken: req.headers.authorization,
organizationId: req.body.organizationId, organizationId: req.body.organizationId,
ipAddress: req.realIp ipAddress: req.realIp
+4 -3
View File
@@ -24,6 +24,7 @@ import {
SRP1DTO, SRP1DTO,
SRPR1Res, SRPR1Res,
TOauthTokenExchangeDTO, TOauthTokenExchangeDTO,
UserAgentType,
VerifyMfaTokenDTO, VerifyMfaTokenDTO,
VerifyMfaTokenRes, VerifyMfaTokenRes,
VerifySignupInviteDTO VerifySignupInviteDTO
@@ -62,7 +63,7 @@ export const useLogin1 = () => {
export const selectOrganization = async (data: { export const selectOrganization = async (data: {
organizationId: string; organizationId: string;
customUserAgent?: string; userAgent?: UserAgentType;
}) => { }) => {
const { data: res } = await apiRequest.post<{ token: string }>( const { data: res } = await apiRequest.post<{ token: string }>(
"/api/v3/auth/select-organization", "/api/v3/auth/select-organization",
@@ -74,11 +75,11 @@ export const selectOrganization = async (data: {
export const useSelectOrganization = () => { export const useSelectOrganization = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation({ return useMutation({
mutationFn: async (details: { organizationId: string; customUserAgent?: string }) => { mutationFn: async (details: { organizationId: string; userAgent?: UserAgentType }) => {
const data = await selectOrganization(details); const data = await selectOrganization(details);
// If a custom user agent is set, then this session is meant for another consuming application, not the web application. // If a custom user agent is set, then this session is meant for another consuming application, not the web application.
if (!details.customUserAgent) { if (!details.userAgent) {
SecurityClient.setToken(data.token); SecurityClient.setToken(data.token);
SecurityClient.setProviderAuthToken(""); SecurityClient.setProviderAuthToken("");
} }
+4
View File
@@ -145,3 +145,7 @@ export type IssueBackupPrivateKeyDTO = {
export type GetBackupEncryptedPrivateKeyDTO = { export type GetBackupEncryptedPrivateKeyDTO = {
verificationToken: string; verificationToken: string;
}; };
export enum UserAgentType {
CLI = "cli"
}
@@ -16,6 +16,7 @@ import { Button, Spinner } from "@app/components/v2";
import { SessionStorageKeys } from "@app/const"; import { SessionStorageKeys } from "@app/const";
import { useUser } from "@app/context"; import { useUser } from "@app/context";
import { useGetOrganizations, useLogoutUser, useSelectOrganization } from "@app/hooks/api"; import { useGetOrganizations, useLogoutUser, useSelectOrganization } from "@app/hooks/api";
import { UserAgentType } from "@app/hooks/api/auth/types";
import { Organization } from "@app/hooks/api/types"; import { Organization } from "@app/hooks/api/types";
import { getAuthToken, isLoggedIn } from "@app/reactQuery"; import { getAuthToken, isLoggedIn } from "@app/reactQuery";
import { navigateUserToOrg } from "@app/views/Login/Login.utils"; import { navigateUserToOrg } from "@app/views/Login/Login.utils";
@@ -70,7 +71,7 @@ export default function LoginPage() {
const { token } = await selectOrg.mutateAsync({ const { token } = await selectOrg.mutateAsync({
organizationId: organization.id, organizationId: organization.id,
customUserAgent: callbackPort ? "cli" : undefined userAgent: callbackPort ? UserAgentType.CLI : undefined
}); });
if (callbackPort) { if (callbackPort) {