Repository: home-assistant/core
File: homeassistant/components/smarla/config_flow.py (Python)

Code before:
        return self.async_show_form(
            step_id="user",
            data_schema=STEP_USER_DATA_SCHEMA,
            errors=errors,
        )

    async def async_step_reauth(
        self, entry_data: Mapping[str, Any]
    ) -> ConfigFlowResult:
        """Perform reauthentication upon an API authentication error."""
        return await self.async_step_reauth_confirm()

    async def async_step_reauth_confirm(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Confirm reauthentication dialog."""
        errors: dict[str, str] = {}

        if user_input is not None:
            raw_token = user_input[CONF_ACCESS_TOKEN]
            errors, serial_number = await self._handle_token(token=raw_token)

            config_entry = self._get_reauth_entry()

            if not errors and serial_number != config_entry.unique_id:
                errors["base"] = "serial_number_mismatch"

            if not errors and serial_number is not None:
                return self.async_update_reload_and_abort(
                    config_entry,
                    data_updates={CONF_ACCESS_TOKEN: raw_token},
                )

        return self.async_show_form(
            step_id="reauth_confirm",
            data_schema=STEP_USER_DATA_SCHEMA,
            errors=errors,
        )


Review comment (security):
use 
```
await self.async_set_unique_id(
self._abort_if_unique_id_mismatch
```
pattern here, you can also check the `self.source` (`SOURCE_USER`/`SOURCE_REAUTH`) in your validation method if that helps

Code after:

        return None

    async def async_step_user(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Handle the initial step."""
        self.errors = {}
        if user_input is not None:
            validated_info = await self._validate_input(user_input)
            if validated_info is not None:
                return self.async_create_entry(
                    title=validated_info["serial_number"],
                    data={CONF_ACCESS_TOKEN: validated_info["token"]},
                )

        return self.async_show_form(
            step_id="user",
            data_schema=STEP_USER_DATA_SCHEMA,
            errors=self.errors,
        )

    async def async_step_reauth(
        self, entry_data: Mapping[str, Any]
    ) -> ConfigFlowResult:
        """Perform reauthentication upon an API authentication error."""
        return await self.async_step_reauth_confirm()

    async def async_step_reauth_confirm(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Confirm reauthentication dialog."""
        self.errors = {}
        if user_input is not None:
            validated_info = await self._validate_input(user_input)
            if validated_info is not None:
                return self.async_update_reload_and_abort(
                    self._get_reauth_entry(),
                    data_updates={CONF_ACCESS_TOKEN: validated_info["token"]},
                )

        return self.async_show_form(
            step_id="reauth_confirm",
            data_schema=STEP_USER_DATA_SCHEMA,
            errors=self.errors,
        )