mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-25 19:10:53 +00:00
handle session creation at the end of linking / finish OIDC flow
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { Alert, AlertType } from "@/components/alert";
|
import { Alert, AlertType } from "@/components/alert";
|
||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { IdpSignin } from "@/components/idp-signin";
|
|
||||||
import { idpTypeToIdentityProviderType, PROVIDER_MAPPING } from "@/lib/idp";
|
import { idpTypeToIdentityProviderType, PROVIDER_MAPPING } from "@/lib/idp";
|
||||||
|
import { createNewSessionForIdp } from "@/lib/server/session";
|
||||||
import {
|
import {
|
||||||
addIDPLink,
|
addIDPLink,
|
||||||
createUser,
|
createUser,
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
import { AutoLinkingOption } from "@zitadel/proto/zitadel/idp/v2/idp_pb";
|
import { AutoLinkingOption } from "@zitadel/proto/zitadel/idp/v2/idp_pb";
|
||||||
import { BrandingSettings } from "@zitadel/proto/zitadel/settings/v2/branding_settings_pb";
|
import { BrandingSettings } from "@zitadel/proto/zitadel/settings/v2/branding_settings_pb";
|
||||||
import { getLocale, getTranslations } from "next-intl/server";
|
import { getLocale, getTranslations } from "next-intl/server";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
async function loginFailed(branding?: BrandingSettings) {
|
async function loginFailed(branding?: BrandingSettings) {
|
||||||
const locale = getLocale();
|
const locale = getLocale();
|
||||||
@@ -50,24 +51,42 @@ export default async function Page(props: {
|
|||||||
|
|
||||||
const { idpInformation, userId } = intent;
|
const { idpInformation, userId } = intent;
|
||||||
|
|
||||||
|
async function continueWithSession(
|
||||||
|
idpIntentId: string,
|
||||||
|
idpIntentToken: string,
|
||||||
|
) {
|
||||||
|
const sessionRedirectResponse = await createNewSessionForIdp({
|
||||||
|
userId,
|
||||||
|
idpIntent: {
|
||||||
|
idpIntentId,
|
||||||
|
idpIntentToken,
|
||||||
|
},
|
||||||
|
authRequestId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
!sessionRedirectResponse ||
|
||||||
|
(sessionRedirectResponse &&
|
||||||
|
"error" in sessionRedirectResponse &&
|
||||||
|
sessionRedirectResponse?.error)
|
||||||
|
) {
|
||||||
|
return loginFailed(branding);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
sessionRedirectResponse &&
|
||||||
|
"redirect" in sessionRedirectResponse &&
|
||||||
|
sessionRedirectResponse?.redirect
|
||||||
|
) {
|
||||||
|
return redirect(sessionRedirectResponse.redirect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// sign in user. If user should be linked continue
|
// sign in user. If user should be linked continue
|
||||||
if (userId && !link) {
|
if (userId && !link) {
|
||||||
// TODO: update user if idp.options.isAutoUpdate is true
|
// TODO: update user if idp.options.isAutoUpdate is true
|
||||||
|
|
||||||
return (
|
await continueWithSession(id, token);
|
||||||
<DynamicTheme branding={branding}>
|
|
||||||
<div className="flex flex-col items-center space-y-4">
|
|
||||||
<h1>{t("loginSuccess.title")}</h1>
|
|
||||||
<div>{t("loginSuccess.description")}</div>
|
|
||||||
|
|
||||||
<IdpSignin
|
|
||||||
userId={userId}
|
|
||||||
idpIntent={{ idpIntentId: id, idpIntentToken: token }}
|
|
||||||
authRequestId={authRequestId}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</DynamicTheme>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!idpInformation) {
|
if (!idpInformation) {
|
||||||
@@ -134,17 +153,7 @@ export default async function Page(props: {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (idpLink) {
|
await continueWithSession(id, token);
|
||||||
return (
|
|
||||||
// TODO: possibily login user now
|
|
||||||
<DynamicTheme branding={branding}>
|
|
||||||
<div className="flex flex-col items-center space-y-4">
|
|
||||||
<h1>{t("linkingSuccess.title")}</h1>
|
|
||||||
<div>{t("linkingSuccess.description")}</div>
|
|
||||||
</div>
|
|
||||||
</DynamicTheme>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user