Unlinking Facebook without Facebook token

We trying to manage an edge case with our unity app where someone has already linked a facebook account to their nakama account, but then changes facebook accounts on the mobile app. The facebook unity api uses the oauth token from the mobile app, so there’s a mismatch in facebook ids and tokens. We want to be able to unlink the facebook id from the current namaka profile without using the current access token - is that possible? We can obviously unlink the facebook id from an account in the console without the access token so we’re hoping that can be done with the client too.

@oscargoldman We originally designed the unlink operation with Facebook to require an OAuth token which would ensure that only the authorized user (according to Facebook) could unlink their account but we’ve had a request like yours come up a few times to allow unlink to take just the Facebook ID only. I think it’d be good to open an issue on the tracker and we can look at an enhancement to the API to support it.

In the meantime the only other way I can think you’d be able to workaround the constraints of the API right now are to use custom SQL from an RPC function. Let me know if you want an example to use.

Thanks Chris, yeah I think this is more a limitation of the facebook unity SDK. Are you opening that issue or shall I? For SQL, I’ve seen the documentation for pure SQL calls in lua - that should be enough for us to make it happen. Thanks again.

What’s the correct way to insert a lua local variable into the sql statement?

Please open the issue on GitHub it will be prioritized differently if it’s opened by you rather than as an internal engineering request.

If you’re good with the SQL approach then check the schema here for how to access the appropriate column and look at this part of the console server impl for how we handle it. Drop your SQL code into this thread if you want a sanity check on it.

oh I see the parameters object.

What’s the correct way to insert a lua local variable into the sql statement?

To insert a SQL-safe variable into the query use placeholder parameters. i.e.

local sql = [[
UPDATE
    users
SET
    facebook_id = $2, update_time = now()
WHERE
    id = $1 AND facebook_id IS NOT NULL
... etc, see console API link for rest of query
]]
local parameters = { context.user_id, some_facebook_id }
local status, res = pcall(nk.sql_exec, query, parameters)
nk.logger_info(("sql exec status %q res %q"):format(status, res))

awesome thanks a bunch

1 Like