mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 06:35:21 +00:00
fix: stale session after logging into CLI
This commit is contained in:
@@ -60,7 +60,10 @@ export const useLogin1 = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const selectOrganization = async (data: { organizationId: string }) => {
|
||||
export const selectOrganization = async (data: {
|
||||
organizationId: string;
|
||||
customUserAgent?: string;
|
||||
}) => {
|
||||
const { data: res } = await apiRequest.post<{ token: string }>(
|
||||
"/api/v3/auth/select-organization",
|
||||
data
|
||||
@@ -71,11 +74,14 @@ export const selectOrganization = async (data: { organizationId: string }) => {
|
||||
export const useSelectOrganization = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (details: { organizationId: string }) => {
|
||||
mutationFn: async (details: { organizationId: string; customUserAgent?: string }) => {
|
||||
const data = await selectOrganization(details);
|
||||
|
||||
SecurityClient.setToken(data.token);
|
||||
SecurityClient.setProviderAuthToken("");
|
||||
// If a custom user agent is set, then this session is meant for another consuming application, not the web application.
|
||||
if (!details.customUserAgent) {
|
||||
SecurityClient.setToken(data.token);
|
||||
SecurityClient.setProviderAuthToken("");
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -68,7 +68,10 @@ export default function LoginPage() {
|
||||
return;
|
||||
}
|
||||
|
||||
const { token } = await selectOrg.mutateAsync({ organizationId: organization.id });
|
||||
const { token } = await selectOrg.mutateAsync({
|
||||
organizationId: organization.id,
|
||||
customUserAgent: callbackPort ? "cli" : undefined
|
||||
});
|
||||
|
||||
if (callbackPort) {
|
||||
const privateKey = localStorage.getItem("PRIVATE_KEY");
|
||||
|
||||
Reference in New Issue
Block a user