> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to: 사용자 로그인 모범 사례

> How to: 사용자 로그인 모범 사례

## 자동으로 기본 사용자를 가져오는 방법 예제

게임은 초기 사용자를 설정해야 합니다. 이 예제는 가능한 한 빨리 이를 달성하는 방법을
보여줍니다. 게임 메뉴가 사용자를 명확하게 식별하는 것으로 "환영"하려는 경우 그리고
UI를 즉시 표시하고 싶지 않은 경우 일반적으로 이 패턴을 따르는 것이 좋습니다.

```c++ theme={null}
HRESULT Identity_TrySignInDefaultUserSilently(_In_ XTaskQueueHandle asyncQueue)
{
    XAsyncBlock* asyncBlock = new XAsyncBlock();
    asyncBlock->queue = asyncQueue;
    asyncBlock->callback = Identity_TrySignInDefaultUserSilently_Callback;

    // Request to silently sign in the default user.
    HRESULT hr = XUserAddAsync(XUserAddOptions::AddDefaultUserSilently, asyncBlock);

    if (FAILED(hr))
    {
        delete asyncBlock;
    }

    return hr;
}

void CALLBACK Identity_TrySignInDefaultUserSilently_Callback(_In_ XAsyncBlock* asyncBlock)
{
    // NOTE: XUserAddResult will add a Ref to the passed-in XUserHandle.
    XUserHandle newUser = nullptr;
    HRESULT hr = XUserAddResult(asyncBlock, &newUser);

    if (SUCCEEDED(hr))
    {
        // TO DO: create Xbox services context and do something with that user.
        // ...
    }
    else 
    {
        // You are here because there's no default user or because of an error.
        // Display some UI, such as "Press A or Enter to continue," and try the sign-in with the UI flow.
    }

    delete asyncBlock;
}
```

## 초기 사용자를 얻는 방법 예제

이전 예제와 마찬가지로, 게임은 초기 사용자를 설정해야 합니다. 이 경우
게임은 사용자를 요청할 때 UI가 표시되도록 허용합니다. 시스템이 기본 사용자를 결정할 수 없는 경우에만
UI가 표시됩니다.

```c++ theme={null}
HRESULT Identity_TrySignInDefaultUser(_In_ XTaskQueueHandle asyncQueue)
{
    XAsyncBlock* asyncBlock = new XAsyncBlock();
    asyncBlock->queue = asyncQueue;
    asyncBlock->callback = Identity_TrySignInDefaultUser_Callback;

    // Request to silently sign in the default user.
    HRESULT hr = XUserAddAsync(XUserAddOptions::AddDefaultUserAllowingUI, asyncBlock);

    if (FAILED(hr))
    {
        delete asyncBlock;
    }

    return hr;
}

void CALLBACK Identity_TrySignInDefaultUser_Callback(_In_ XAsyncBlock* asyncBlock)
{
    // NOTE: XUserAddResult will add a Ref to the passed-in XUserHandle.
    XUserHandle newUser = nullptr;
    HRESULT hr = XUserAddResult(asyncBlock, &newUser);

    if (SUCCEEDED(hr))
    {
        // TO DO: create Xbox services context and do something with that user.
        // ...
    }
    else
    {
        // You are probably here because someone canceled out of the UI flow to 
        // sign in or an expected error occurred.
        // Display some UI, such as "Press A or Enter to continue," and try the sign-in 
        // again with the UI flow.
    }

    delete asyncBlock;
}

```

## 참고 항목

[사용자 ID 및 XUser](/build/core-features/common/user/player-identity-xuser)


## Related topics

- [사용자](/ko/build/core-features/common/user/user-toc.md)
- [사용자 ID 및 XUser](/ko/build/core-features/common/user/player-identity-xuser.md)
- [로그인 기본 사항 및 모범 사례](/ko/services/playfab/identity/player-identity/login/login-basics-best-practices.md)
- [사용자 로그인](/ko/services/xbox-services/fundamentals/identity/auth/live-authentication-nav.md)
- [게임 스트리밍 사용자 지정 해상도 모범 사례](/ko/build/core-features/common/game-streaming/game-streaming-custom-resolution-best-practices.md)
