Unverified Commit dc526a46 authored by Fernando Takagi's avatar Fernando Takagi Committed by GitHub
Browse files

Optional token parameter on unlink functions. (#922)

parent cefc7d3f
Loading
Loading
Loading
Loading
+115 −107
Original line number Diff line number Diff line
@@ -28,24 +28,21 @@ import (
)

func UnlinkApple(ctx context.Context, logger *zap.Logger, db *sql.DB, config Config, socialClient *social.Client, id uuid.UUID, token string) error {
	if config.GetSocial().Apple.BundleId == "" {
		return status.Error(codes.FailedPrecondition, "Apple authentication is not configured.")
	}

	if token == "" {
		return status.Error(codes.InvalidArgument, "Apple ID token is required.")
	}
	params := []any{id}
	query := `UPDATE users SET apple_id = NULL, update_time = now() WHERE id = $1`

	if token != "" {
		profile, err := socialClient.CheckAppleToken(ctx, config.GetSocial().Apple.BundleId, token)
		if err != nil {
			logger.Info("Could not authenticate Apple profile.", zap.Error(err))
			return status.Error(codes.Unauthenticated, "Could not authenticate Apple profile.")
		}
		params = append(params, profile.ID)
		query = query + ` AND apple_id = $2`
	}

	res, err := db.ExecContext(ctx, `UPDATE users SET apple_id = NULL, update_time = now()
WHERE id = $1
AND apple_id = $2
AND ((custom_id IS NOT NULL
	query = query +
		` AND ((custom_id IS NOT NULL
      OR facebook_id IS NOT NULL
      OR facebook_instant_game_id IS NOT NULL
      OR google_id IS NOT NULL
@@ -53,7 +50,9 @@ AND ((custom_id IS NOT NULL
      OR steam_id IS NOT NULL
      OR email IS NOT NULL)
     OR
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`, id, profile.ID)
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`

	res, err := db.ExecContext(ctx, query, params...)

	if err != nil {
		logger.Error("Could not unlink Apple ID.", zap.Error(err), zap.Any("input", token))
@@ -65,14 +64,16 @@ AND ((custom_id IS NOT NULL
}

func UnlinkCustom(ctx context.Context, logger *zap.Logger, db *sql.DB, id uuid.UUID, customID string) error {
	if customID == "" {
		return status.Error(codes.InvalidArgument, "An ID must be supplied.")
	params := []any{id}
	query := `UPDATE users SET custom_id = NULL, update_time = now() WHERE id = $1`

	if customID != "" {
		params = append(params, customID)
		query = query + ` AND custom_id = $2`
	}

	res, err := db.ExecContext(ctx, `UPDATE users SET custom_id = NULL, update_time = now()
WHERE id = $1
AND custom_id = $2
AND ((apple_id IS NOT NULL
	query = query +
		` AND ((apple_id IS NOT NULL
      OR facebook_id IS NOT NULL
      OR facebook_instant_game_id IS NOT NULL
      OR google_id IS NOT NULL
@@ -80,7 +81,9 @@ AND ((apple_id IS NOT NULL
      OR steam_id IS NOT NULL
      OR email IS NOT NULL)
     OR
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`, id, customID)
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`

	res, err := db.ExecContext(ctx, query, params...)

	if err != nil {
		logger.Error("Could not unlink custom ID.", zap.Error(err), zap.Any("input", customID))
@@ -145,15 +148,17 @@ AND (EXISTS (SELECT id FROM users WHERE id = $1 AND
}

func UnlinkEmail(ctx context.Context, logger *zap.Logger, db *sql.DB, id uuid.UUID, email string) error {
	if email == "" {
		return status.Error(codes.InvalidArgument, "Both email and password must be supplied.")
	}
	params := []any{id}
	query := `UPDATE users SET email = NULL, password = NULL, update_time = now() WHERE id = $1`

	if email != "" {
		cleanEmail := strings.ToLower(email)
		params = append(params, cleanEmail)
		query = query + ` AND email = $2`
	}

	res, err := db.ExecContext(ctx, `UPDATE users SET email = NULL, password = NULL, update_time = now()
WHERE id = $1
AND email = $2
AND ((apple_id IS NOT NULL
	query = query +
		` AND ((apple_id IS NOT NULL
      OR facebook_id IS NOT NULL
      OR facebook_instant_game_id IS NOT NULL
      OR google_id IS NOT NULL
@@ -161,7 +166,9 @@ AND ((apple_id IS NOT NULL
      OR steam_id IS NOT NULL
      OR custom_id IS NOT NULL)
     OR
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`, id, cleanEmail)
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`

	res, err := db.ExecContext(ctx, query, params...)

	if err != nil {
		logger.Error("Could not unlink email.", zap.Error(err), zap.Any("input", email))
@@ -173,10 +180,10 @@ AND ((apple_id IS NOT NULL
}

func UnlinkFacebook(ctx context.Context, logger *zap.Logger, db *sql.DB, socialClient *social.Client, appId string, id uuid.UUID, token string) error {
	if token == "" {
		return status.Error(codes.InvalidArgument, "Facebook access token is required.")
	}
	params := []any{id}
	query := `UPDATE users SET facebook_id = NULL, update_time = now() WHERE id = $1`

	if token != "" {
		facebookProfile, err := socialClient.CheckFacebookLimitedLoginToken(ctx, appId, token)
		if err != nil {
			facebookProfile, err = socialClient.GetFacebookProfile(ctx, token)
@@ -185,11 +192,12 @@ func UnlinkFacebook(ctx context.Context, logger *zap.Logger, db *sql.DB, socialC
				return status.Error(codes.Unauthenticated, "Could not authenticate Facebook profile.")
			}
		}
		params = append(params, facebookProfile.ID)
		query = query + ` AND facebook_id = $2`
	}

	res, err := db.ExecContext(ctx, `UPDATE users SET facebook_id = NULL, update_time = now()
WHERE id = $1
AND facebook_id = $2
AND ((apple_id IS NOT NULL
	query = query +
		` AND ((apple_id IS NOT NULL
      OR custom_id IS NOT NULL
      OR facebook_instant_game_id IS NOT NULL
      OR google_id IS NOT NULL
@@ -197,7 +205,9 @@ AND ((apple_id IS NOT NULL
      OR steam_id IS NOT NULL
      OR email IS NOT NULL)
     OR
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`, id, facebookProfile.ID)
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`

	res, err := db.ExecContext(ctx, query, params...)

	if err != nil {
		logger.Error("Could not unlink Facebook ID.", zap.Error(err), zap.Any("input", token))
@@ -209,20 +219,21 @@ AND ((apple_id IS NOT NULL
}

func UnlinkFacebookInstantGame(ctx context.Context, logger *zap.Logger, db *sql.DB, config Config, socialClient *social.Client, id uuid.UUID, signedPlayerInfo string) error {
	if signedPlayerInfo == "" {
		return status.Error(codes.InvalidArgument, "Signed Player Info for a Facebook Instant Game is required.")
	}
	params := []any{id}
	query := `UPDATE users SET facebook_instant_game_id = NULL, update_time = now() WHERE id = $1`

	if signedPlayerInfo != "" {
		facebookInstantGameID, err := socialClient.ExtractFacebookInstantGameID(signedPlayerInfo, config.GetSocial().FacebookInstantGame.AppSecret)
		if err != nil {
			logger.Info("Could not authenticate Facebook Instant Game profile.", zap.Error(err))
			return status.Error(codes.Unauthenticated, "Could not authenticate Facebook Instant Game profile.")
		}
		params = append(params, facebookInstantGameID)
		query = query + ` AND facebook_instant_game_id = $2`
	}

	res, err := db.ExecContext(ctx, `UPDATE users SET facebook_instant_game_id = NULL, update_time = now()
WHERE id = $1
AND facebook_instant_game_id = $2
AND ((apple_id IS NOT NULL
	query = query +
		` AND ((apple_id IS NOT NULL
      OR custom_id IS NOT NULL
      OR google_id IS NOT NULL
      OR facebook_id IS NOT NULL
@@ -230,7 +241,9 @@ AND ((apple_id IS NOT NULL
      OR steam_id IS NOT NULL
      OR email IS NOT NULL)
     OR
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`, id, facebookInstantGameID)
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`

	res, err := db.ExecContext(ctx, query, params...)

	if err != nil {
		logger.Error("Could not unlink Facebook Instant Game ID.", zap.Error(err), zap.Any("input", signedPlayerInfo))
@@ -242,30 +255,21 @@ AND ((apple_id IS NOT NULL
}

func UnlinkGameCenter(ctx context.Context, logger *zap.Logger, db *sql.DB, socialClient *social.Client, id uuid.UUID, playerID string, bundleID string, timestamp int64, salt string, signature string, publicKeyURL string) error {
	if bundleID == "" {
		return status.Error(codes.InvalidArgument, "GameCenter bundle ID is required.")
	} else if playerID == "" {
		return status.Error(codes.InvalidArgument, "GameCenter player ID is required.")
	} else if publicKeyURL == "" {
		return status.Error(codes.InvalidArgument, "GameCenter public key URL is required.")
	} else if salt == "" {
		return status.Error(codes.InvalidArgument, "GameCenter salt is required.")
	} else if signature == "" {
		return status.Error(codes.InvalidArgument, "GameCenter signature is required.")
	} else if timestamp == 0 {
		return status.Error(codes.InvalidArgument, "GameCenter timestamp is required.")
	}
	params := []any{id}
	query := `UPDATE users SET gamecenter_id = NULL, update_time = now() WHERE id = $1`

	if bundleID != "" && playerID != "" && publicKeyURL != "" && salt != "" && signature != "" && timestamp != 0 {
		valid, err := socialClient.CheckGameCenterID(ctx, playerID, bundleID, timestamp, salt, signature, publicKeyURL)
		if !valid || err != nil {
			logger.Info("Could not authenticate GameCenter profile.", zap.Error(err), zap.Bool("valid", valid))
			return status.Error(codes.Unauthenticated, "Could not authenticate GameCenter profile.")
		}
		params = append(params, playerID)
		query = query + ` AND gamecenter_id = $2`
	}

	res, err := db.ExecContext(ctx, `UPDATE users SET gamecenter_id = NULL, update_time = now()
WHERE id = $1
AND gamecenter_id = $2
AND ((apple_id IS NOT NULL
	query = query +
		` AND ((apple_id IS NOT NULL
      OR custom_id IS NOT NULL
      OR google_id IS NOT NULL
      OR facebook_id IS NOT NULL
@@ -273,7 +277,9 @@ AND ((apple_id IS NOT NULL
      OR steam_id IS NOT NULL
      OR email IS NOT NULL)
     OR
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`, id, playerID)
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`

	res, err := db.ExecContext(ctx, query, params...)

	if err != nil {
		logger.Error("Could not unlink GameCenter ID.", zap.Error(err), zap.Any("input", playerID))
@@ -285,20 +291,21 @@ AND ((apple_id IS NOT NULL
}

func UnlinkGoogle(ctx context.Context, logger *zap.Logger, db *sql.DB, socialClient *social.Client, id uuid.UUID, token string) error {
	if token == "" {
		return status.Error(codes.InvalidArgument, "Google access token is required.")
	}
	params := []any{id}
	query := `UPDATE users SET google_id = NULL, update_time = now() WHERE id = $1`

	if token != "" {
		googleProfile, err := socialClient.CheckGoogleToken(ctx, token)
		if err != nil {
			logger.Info("Could not authenticate Google profile.", zap.Error(err))
			return status.Error(codes.Unauthenticated, "Could not authenticate Google profile.")
		}
		params = append(params, googleProfile.Sub)
		query = query + ` AND google_id = $2`
	}

	res, err := db.ExecContext(ctx, `UPDATE users SET google_id = NULL, update_time = now()
WHERE id = $1
AND google_id = $2
AND ((apple_id IS NOT NULL
	query = query +
		` AND ((apple_id IS NOT NULL
      OR custom_id IS NOT NULL
      OR gamecenter_id IS NOT NULL
      OR facebook_id IS NOT NULL
@@ -306,7 +313,9 @@ AND ((apple_id IS NOT NULL
      OR steam_id IS NOT NULL
      OR email IS NOT NULL)
     OR
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`, id, googleProfile.Sub)
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`

	res, err := db.ExecContext(ctx, query, params...)

	if err != nil {
		logger.Error("Could not unlink Google ID.", zap.Error(err), zap.Any("input", token))
@@ -318,24 +327,21 @@ AND ((apple_id IS NOT NULL
}

func UnlinkSteam(ctx context.Context, logger *zap.Logger, db *sql.DB, config Config, socialClient *social.Client, id uuid.UUID, token string) error {
	if config.GetSocial().Steam.PublisherKey == "" || config.GetSocial().Steam.AppID == 0 {
		return status.Error(codes.FailedPrecondition, "Steam authentication is not configured.")
	}

	if token == "" {
		return status.Error(codes.InvalidArgument, "Steam access token is required.")
	}
	params := []any{id}
	query := `UPDATE users SET steam_id = NULL, update_time = now() WHERE id = $1`

	if token != "" {
		steamProfile, err := socialClient.GetSteamProfile(ctx, config.GetSocial().Steam.PublisherKey, config.GetSocial().Steam.AppID, token)
		if err != nil {
			logger.Info("Could not authenticate Steam profile.", zap.Error(err))
			return status.Error(codes.Unauthenticated, "Could not authenticate Steam profile.")
		}
		params = append(params, strconv.FormatUint(steamProfile.SteamID, 10))
		query = query + ` AND steam_id = $2`
	}

	res, err := db.ExecContext(ctx, `UPDATE users SET steam_id = NULL, update_time = now()
WHERE id = $1
AND steam_id = $2
AND ((apple_id IS NOT NULL
	query = query +
		` AND ((apple_id IS NOT NULL
      OR custom_id IS NOT NULL
      OR gamecenter_id IS NOT NULL
      OR facebook_id IS NOT NULL
@@ -343,7 +349,9 @@ AND ((apple_id IS NOT NULL
      OR google_id IS NOT NULL
      OR email IS NOT NULL)
     OR
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`, id, strconv.FormatUint(steamProfile.SteamID, 10))
     EXISTS (SELECT id FROM user_device WHERE user_id = $1 LIMIT 1))`

	res, err := db.ExecContext(ctx, query, params...)

	if err != nil {
		logger.Error("Could not unlink Steam ID.", zap.Error(err), zap.Any("input", token))
+7 −7
Original line number Diff line number Diff line
@@ -836,7 +836,7 @@ func (n *RuntimeGoNakamaModule) ReadFile(relPath string) (*os.File, error) {
// @summary Unlink Apple authentication from a user ID.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param userId(type=string) The user ID to be unlinked.
// @param token(type=string) Apple sign in token.
// @param token(type=string, optional=true) Apple sign in token.
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeGoNakamaModule) UnlinkApple(ctx context.Context, userID, token string) error {
	id, err := uuid.FromString(userID)
@@ -851,7 +851,7 @@ func (n *RuntimeGoNakamaModule) UnlinkApple(ctx context.Context, userID, token s
// @summary Unlink custom authentication from a user ID.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param userId(type=string) The user ID to be unlinked.
// @param customId(type=string) Custom ID to be unlinked from the user.
// @param customId(type=string, optional=true) Custom ID to be unlinked from the user.
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeGoNakamaModule) UnlinkCustom(ctx context.Context, userID, customID string) error {
	id, err := uuid.FromString(userID)
@@ -881,7 +881,7 @@ func (n *RuntimeGoNakamaModule) UnlinkDevice(ctx context.Context, userID, device
// @summary Unlink email authentication from a user ID.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param userId(type=string) The user ID to be unlinked.
// @param email(type=string) Email to be unlinked from the user.
// @param email(type=string, optional=true) Email to be unlinked from the user.
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeGoNakamaModule) UnlinkEmail(ctx context.Context, userID, email string) error {
	id, err := uuid.FromString(userID)
@@ -896,7 +896,7 @@ func (n *RuntimeGoNakamaModule) UnlinkEmail(ctx context.Context, userID, email s
// @summary Unlink Facebook authentication from a user ID.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param userId(type=string) The user ID to be unlinked.
// @param token(type=string) Facebook OAuth or Limited Login (JWT) access token.
// @param token(type=string, optional=true) Facebook OAuth or Limited Login (JWT) access token.
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeGoNakamaModule) UnlinkFacebook(ctx context.Context, userID, token string) error {
	id, err := uuid.FromString(userID)
@@ -911,7 +911,7 @@ func (n *RuntimeGoNakamaModule) UnlinkFacebook(ctx context.Context, userID, toke
// @summary Unlink Facebook Instant Game authentication from a user ID.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param userId(type=string) The user ID to be unlinked.
// @param playerInfo(type=string) Facebook player info.
// @param playerInfo(type=string, optional=true) Facebook player info.
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeGoNakamaModule) UnlinkFacebookInstantGame(ctx context.Context, userID, signedPlayerInfo string) error {
	id, err := uuid.FromString(userID)
@@ -946,7 +946,7 @@ func (n *RuntimeGoNakamaModule) UnlinkGameCenter(ctx context.Context, userID, pl
// @summary Unlink Google authentication from a user ID.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param userId(type=string) The user ID to be unlinked.
// @param token(type=string) Google OAuth access token.
// @param token(type=string, optional=true) Google OAuth access token.
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeGoNakamaModule) UnlinkGoogle(ctx context.Context, userID, token string) error {
	id, err := uuid.FromString(userID)
@@ -961,7 +961,7 @@ func (n *RuntimeGoNakamaModule) UnlinkGoogle(ctx context.Context, userID, token
// @summary Unlink Steam authentication from a user ID.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param userId(type=string) The user ID to be unlinked.
// @param token(type=string) Steam access token.
// @param token(type=string, optional=true) Steam access token.
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeGoNakamaModule) UnlinkSteam(ctx context.Context, userID, token string) error {
	id, err := uuid.FromString(userID)
+45 −45
Original line number Diff line number Diff line
@@ -2427,9 +2427,9 @@ func (n *runtimeJavascriptNakamaModule) unlinkApple(r *goja.Runtime) func(goja.F
			panic(r.NewTypeError("invalid user id"))
		}

		token := getJsString(r, f.Argument(1))
		if token == "" {
			panic(r.NewTypeError("expects token string"))
		token := ""
		if f.Argument(1) != goja.Undefined() {
			token = getJsString(r, f.Argument(1))
		}

		if err := UnlinkApple(n.ctx, n.logger, n.db, n.config, n.socialClient, id, token); err != nil {
@@ -2443,7 +2443,7 @@ func (n *runtimeJavascriptNakamaModule) unlinkApple(r *goja.Runtime) func(goja.F
// @group authenticate
// @summary Unlink custom authentication from a user ID.
// @param userId(type=string) The user ID to be unlinked.
// @param customId(type=string) Custom ID to be unlinked from the user.
// @param customId(type=string, optional=true) Custom ID to be unlinked from the user.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) unlinkCustom(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -2453,9 +2453,9 @@ func (n *runtimeJavascriptNakamaModule) unlinkCustom(r *goja.Runtime) func(goja.
			panic(r.NewTypeError("invalid user id"))
		}

		customID := getJsString(r, f.Argument(1))
		if customID == "" {
			panic(r.NewTypeError("expects custom ID string"))
		customID := ""
		if f.Argument(1) != goja.Undefined() {
			customID = getJsString(r, f.Argument(1))
		}

		if err := UnlinkCustom(n.ctx, n.logger, n.db, id, customID); err != nil {
@@ -2495,7 +2495,7 @@ func (n *runtimeJavascriptNakamaModule) unlinkDevice(r *goja.Runtime) func(goja.
// @group authenticate
// @summary Unlink email authentication from a user ID.
// @param userId(type=string) The user ID to be unlinked.
// @param email(type=string) Email to be unlinked from the user.
// @param email(type=string, optional=true) Email to be unlinked from the user.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) unlinkEmail(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -2505,9 +2505,9 @@ func (n *runtimeJavascriptNakamaModule) unlinkEmail(r *goja.Runtime) func(goja.F
			panic(r.NewTypeError("invalid user id"))
		}

		email := getJsString(r, f.Argument(1))
		if email == "" {
			panic(r.NewTypeError("expects email string"))
		email := ""
		if f.Argument(1) != goja.Undefined() {
			email = getJsString(r, f.Argument(1))
		}

		if err := UnlinkEmail(n.ctx, n.logger, n.db, id, email); err != nil {
@@ -2521,7 +2521,7 @@ func (n *runtimeJavascriptNakamaModule) unlinkEmail(r *goja.Runtime) func(goja.F
// @group authenticate
// @summary Unlink Facebook authentication from a user ID.
// @param userId(type=string) The user ID to be unlinked.
// @param token(type=string) Facebook OAuth or Limited Login (JWT) access token.
// @param token(type=string, optional=true) Facebook OAuth or Limited Login (JWT) access token.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) unlinkFacebook(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -2531,9 +2531,9 @@ func (n *runtimeJavascriptNakamaModule) unlinkFacebook(r *goja.Runtime) func(goj
			panic(r.NewTypeError("invalid user id"))
		}

		token := getJsString(r, f.Argument(1))
		if token == "" {
			panic(r.NewTypeError("expects token string"))
		token := ""
		if f.Argument(1) != goja.Undefined() {
			token = getJsString(r, f.Argument(1))
		}

		if err := UnlinkFacebook(n.ctx, n.logger, n.db, n.socialClient, n.config.GetSocial().FacebookLimitedLogin.AppId, id, token); err != nil {
@@ -2547,7 +2547,7 @@ func (n *runtimeJavascriptNakamaModule) unlinkFacebook(r *goja.Runtime) func(goj
// @group authenticate
// @summary Unlink Facebook Instant Game authentication from a user ID.
// @param userId(type=string) The user ID to be unlinked.
// @param playerInfo(type=string) Facebook player info.
// @param playerInfo(type=string, optional=true) Facebook player info.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) unlinkFacebookInstantGame(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -2557,9 +2557,9 @@ func (n *runtimeJavascriptNakamaModule) unlinkFacebookInstantGame(r *goja.Runtim
			panic(r.NewTypeError("invalid user id"))
		}

		signedPlayerInfo := getJsString(r, f.Argument(1))
		if signedPlayerInfo == "" {
			panic(r.NewTypeError("expects signed player info string"))
		signedPlayerInfo := ""
		if f.Argument(1) != goja.Undefined() {
			signedPlayerInfo = getJsString(r, f.Argument(1))
		}

		if err := UnlinkFacebookInstantGame(n.ctx, n.logger, n.db, n.config, n.socialClient, id, signedPlayerInfo); err != nil {
@@ -2588,29 +2588,29 @@ func (n *runtimeJavascriptNakamaModule) unlinkGameCenter(r *goja.Runtime) func(g
			panic(r.NewTypeError("invalid user id"))
		}

		playerID := getJsString(r, f.Argument(1))
		if playerID == "" {
			panic(r.NewTypeError("expects player ID string"))
		playerID := ""
		if f.Argument(1) != goja.Undefined() {
			playerID = getJsString(r, f.Argument(1))
		}
		bundleID := getJsString(r, f.Argument(2))
		if bundleID == "" {
			panic(r.NewTypeError("expects bundle ID string"))
		bundleID := ""
		if f.Argument(2) != goja.Undefined() {
			bundleID = getJsString(r, f.Argument(2))
		}
		ts := getJsInt(r, f.Argument(3))
		if ts == 0 {
			panic(r.NewTypeError("expects timestamp value"))
		ts := int64(0)
		if f.Argument(3) != goja.Undefined() {
			ts = getJsInt(r, f.Argument(3))
		}
		salt := getJsString(r, f.Argument(4))
		if salt == "" {
			panic(r.NewTypeError("expects salt string"))
		salt := ""
		if f.Argument(4) != goja.Undefined() {
			salt = getJsString(r, f.Argument(4))
		}
		signature := getJsString(r, f.Argument(5))
		if signature == "" {
			panic(r.NewTypeError("expects signature string"))
		signature := ""
		if f.Argument(5) != goja.Undefined() {
			signature = getJsString(r, f.Argument(5))
		}
		publicKeyURL := getJsString(r, f.Argument(6))
		if publicKeyURL == "" {
			panic(r.NewTypeError("expects public key URL string"))
		publicKeyURL := ""
		if f.Argument(6) != goja.Undefined() {
			publicKeyURL = getJsString(r, f.Argument(6))
		}

		if err := UnlinkGameCenter(n.ctx, n.logger, n.db, n.socialClient, id, playerID, bundleID, ts, salt, signature, publicKeyURL); err != nil {
@@ -2624,7 +2624,7 @@ func (n *runtimeJavascriptNakamaModule) unlinkGameCenter(r *goja.Runtime) func(g
// @group authenticate
// @summary Unlink Google authentication from a user ID.
// @param userId(type=string) The user ID to be unlinked.
// @param token(type=string) Google OAuth access token.
// @param token(type=string, optional=true) Google OAuth access token.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) unlinkGoogle(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -2634,9 +2634,9 @@ func (n *runtimeJavascriptNakamaModule) unlinkGoogle(r *goja.Runtime) func(goja.
			panic(r.NewTypeError("invalid user id"))
		}

		token := getJsString(r, f.Argument(1))
		if token == "" {
			panic(r.NewTypeError("expects token string"))
		token := ""
		if f.Argument(1) != goja.Undefined() {
			token = getJsString(r, f.Argument(1))
		}

		if err := UnlinkGoogle(n.ctx, n.logger, n.db, n.socialClient, id, token); err != nil {
@@ -2650,7 +2650,7 @@ func (n *runtimeJavascriptNakamaModule) unlinkGoogle(r *goja.Runtime) func(goja.
// @group authenticate
// @summary Unlink Steam authentication from a user ID.
// @param userId(type=string) The user ID to be unlinked.
// @param token(type=string) Steam access token.
// @param token(type=string, optional=true) Steam access token.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) unlinkSteam(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -2660,9 +2660,9 @@ func (n *runtimeJavascriptNakamaModule) unlinkSteam(r *goja.Runtime) func(goja.F
			panic(r.NewTypeError("invalid user id"))
		}

		token := getJsString(r, f.Argument(1))
		if token == "" {
			panic(r.NewTypeError("expects token string"))
		token := ""
		if f.Argument(1) != goja.Undefined() {
			token = getJsString(r, f.Argument(1))
		}

		if err := UnlinkSteam(n.ctx, n.logger, n.db, n.config, n.socialClient, id, token); err != nil {
+28 −56

File changed.

Preview size limit exceeded, changes collapsed.