Skip to content

beamable-sdk / services / AuthService

Class: AuthService

Defined in: src/services/AuthService.ts:52

Extends

Constructors

Constructor

new AuthService(props): AuthService

Defined in: src/services/AuthService.ts:53

Parameters

props

ApiServiceProps

Returns

AuthService

Overrides

ApiService.constructor

Methods

handleThirdPartyAuthFlow()

handleThirdPartyAuthFlow(params): Promise<void>

Defined in: src/services/AuthService.ts:247

Orchestrates a third-party login / linking flow

Parameters

params

LoginWithThirdPartyParams

Returns

Promise<void>

Remarks

This method handles the logic for logging in with a third-party provider or linking a third-party account to an existing Beamable account. This will only work in the client SDK and auto refresh the Beam instance.

Example

await beam.auth.handleThirdPartyAuthFlow({
  provider: ThirdPartyAuthProvider.Google,
  token: 'google-auth-token',
});

Throws

If the authentication flow fails.


loginAsGuest()

loginAsGuest(): Promise<TokenResponse>

Defined in: src/services/AuthService.ts:71

Authenticates a guest user.

Returns

Promise<TokenResponse>

Example

const tokenResponse = await beam.auth.loginAsGuest();
await beam.refresh(tokenResponse);

Throws

If the authentication fails.


loginWithEmail()

loginWithEmail(params): Promise<TokenResponse>

Defined in: src/services/AuthService.ts:96

Authenticates a user with an email and password.

Parameters

params

LoginWithEmailParams

Returns

Promise<TokenResponse>

Example

const tokenResponse = await beam.auth.loginWithEmail({
  email: "user@example.com",
  password: "password123"
});
await beam.refresh(tokenResponse);

Throws

If the authentication fails.


loginWithExternalIdentity()

loginWithExternalIdentity(params): Promise<TokenResponse>

Defined in: src/services/AuthService.ts:159

Authenticates a user with an external identity.

Parameters

params

LoginWithExternalIdentityParams

Returns

Promise<TokenResponse>

Example

const tokenResponse = await beam.auth.loginWithExternalIdentity({
  externalToken: 'acme-auth-token',
  providerService: acmeServiceClient.serviceName,
  providerNamespace: acmeServiceClient.federationIds.acme,
  // optional
  challengeHandler: (challenge) => {
    // Handle the challenge, e.g., by displaying a CAPTCHA or OTP to the user
    return prompt(challenge);
  },
});
await beam.refresh(tokenResponse);

Throws

If the authentication fails.


loginWithThirdParty()

loginWithThirdParty(params): Promise<TokenResponse>

Defined in: src/services/AuthService.ts:123

Authenticates a user with a third-party provider (e.g., Google, Facebook).

Parameters

params

LoginWithThirdPartyParams

Returns

Promise<TokenResponse>

Example

const tokenResponse = await beam.auth.loginWithThirdParty({
  provider: ThirdPartyAuthProvider.Google,
  token: "google-auth-token"
});
await beam.refresh(tokenResponse);

Throws

If the authentication fails.


refreshAuthToken()

refreshAuthToken(params): Promise<TokenResponse>

Defined in: src/services/AuthService.ts:313

Requests a new access token using the stored refresh token.

Parameters

params

RefreshTokenParams

Returns

Promise<TokenResponse>

Example

const tokenResponse = await beam.auth.refreshAuthToken({
  refreshToken: "your-refresh-token"
});

Throws

If the refresh token is invalid or the request fails.