1 The version we used before was Web3Auto Unity3D SDK V1.2.
2 We used Lua to implement the UI logic. The login process calls the self.web3Auth:login(options); function from UIWeb3AuthLogin.lua’s UIWeb3AuthLogin:NormalLogin at the last line to invoke the login function in Web3Auth.cs and achieve the login process. The entire process was written with reference to examples from the SDK.
3 The console did not show any exceptions or information.
4 Whenever there seems to be a login issue, it appears simultaneously in both the Unity3D client and the web login. The situation where the login page cannot be opened occurs. Thus, it’s less likely related to the Unity3D and web login processes. We suspect it’s more likely an issue with the server logic of Web3Auth.
@sharon Thanks for reaching out.
Can you share the console logs from the error page?
Also, share your implementation code.
-- 登陆界面
local BaseView = require("Framework.UI.UIManager.BaseView")
---@class UIWeb3AuthLogin : BaseView
local UIWeb3AuthLogin = Class("UIWeb3AuthLogin", BaseView)
local LoggerTag = "UIWeb3AuthLogin"
local AccountType = Def.SDKDef.AccountType
local LoginType = { Normal = 1, History = 2 }
local AccountIcon = {
[CS.Provider.GOOGLE:GetHashCode()] = "Assets/ResourcesAb/Textures/UI/Common_bg/Common_sign_10.png",
[CS.Provider.FACEBOOK:GetHashCode()] = "Assets/ResourcesAb/Textures/UI/Common_bg/Common_sign_11.png",
[CS.Provider.DISCORD:GetHashCode()] = "Assets/ResourcesAb/Textures/UI/Common_bg/Common_sign_11.png",
}
-- 支持的登录方式列表
local verifierList = {
CS.LoginVerifier("Google", CS.Provider.GOOGLE),
CS.LoginVerifier("Facebook", CS.Provider.FACEBOOK),
CS.LoginVerifier("Discord", CS.Provider.DISCORD),
CS.LoginVerifier("Hosted Email Passwordless", CS.Provider.EMAIL_PASSWORDLESS)
}
function UIWeb3AuthLogin:OnCreate()
self:RegisterBtnClick("btnClose", function() self:Close() end)
self:RegisterBtnClick("btnRemember", function()
self.bRemember = not self.bRemember
self:SetRememberBtnActive(self.bRemember, true)
end)
self:RegisterBtnClick("btnGoogle", function() self:OnBtnClick(1) end)
self:RegisterBtnClick("btnFacebook", function() self:OnBtnClick(2) end)
self:RegisterBtnClick("btnDiscord", function() self:OnBtnClick(3) end)
self:RegisterBtnClick("btnSendEmail", function()
if not UIUtil.IsEMail(self.inputEmail.text) then
return
end
self:OnBtnClick(4)
end)
self:RegisterBtnClick("btnSwitch", function()
self:SwitchLoginPage(LoginType.Normal)
self.funHistoryLogin = nil
end)
self:InitWeb3Auth()
self:RegisterInputFieldOnValueChanged("inputEmail", function(strValue)
if strValue == "" then
self:SetVisible("txtTips", false)
self:SetVisible("imgSendInactiveBg", false)
return
end
if not UIUtil.IsEMail(strValue) then
self:SetVisible("txtTips", true)
self:SetVisible("imgSendInactiveBg", true)
--FastTips:Show(GetStringByKey("UILoginNFTPanel_Emailincorrect","请入邮箱为空,或邮箱格式不正确"))
else
self:SetVisible("txtTips", false)
self:SetVisible("imgSendInactiveBg", false)
end
end)
self.inputEmail = self:FindUI("inputEmail")
self.imgSendInActiveBg = self:FindUI("imgSendInactiveBg")
self:SetVisible("Item3", not Platform.IsIos())
end
---@param funCallback fun(nSdkRet:error_t, strJson:string)
function UIWeb3AuthLogin:OnOpen(funCallback)
self.funCallback = funCallback
self.loginProviderInfo = nil
local strPrevEmail = LocalStorage.getString("UISign_RemEmailAddr")
self.bRemember = strPrevEmail ~= ""
self:SetVisible("imgSendInactiveBg", not UIUtil.IsEMail(strPrevEmail))
self.inputEmail.text = strPrevEmail
self:SetRememberBtnActive(self.bRemember)
---@type SdkWeb3Auth
local tSdk = SDKLogic:GetSdkInstance(AccountType.Web3Auth)
if not tSdk then
Logger:Error(LoggerTag, "OnLogin tSdk is nil")
self:SwitchLoginPage(LoginType.Normal)
return
end
local tbLuaResponseHistory, tbWeb3AuthFullRspHistory = tSdk:LoadHistoryLogin()
if tbLuaResponseHistory ~= nil and next(tbLuaResponseHistory) and tbWeb3AuthFullRspHistory ~= nil and next(tbWeb3AuthFullRspHistory) then
-- 历史登录
self:SwitchLoginPage(LoginType.History)
self:SetHistoryContainerUI(tbLuaResponseHistory)
self.funHistoryLogin = function(nRet, tbLuaResponse)
if nRet ~= 0 or not tbLuaResponse then
self:OnFailedLogin(tbLuaResponse or { provider = tbLuaResponseHistory.provider })
Logger:Debug(LoggerTag, "TryLoginWithHistory out of time. Need re-login")
self:SwitchLoginPage(LoginType.Normal)
return
end
self:OnSuccessLogin(tbLuaResponse)
end
Timer:DelayCall(3, function()
if not self.panel.isShow or self.funHistoryLogin == nil then
return
end
tSdk:RefreshTokenFromMugen(tbLuaResponseHistory, tbWeb3AuthFullRspHistory, function(nRet, tbLuaResponse)
if self.funHistoryLogin then
self.funHistoryLogin(nRet, tbLuaResponse)
end
end)
end)
else
-- 常规登录
self:SwitchLoginPage(LoginType.Normal)
end
end
function UIWeb3AuthLogin:OnClose()
self.loginProviderInfo = nil
if self.bRemember then
LocalStorage.setString("UISign_RemEmailAddr", self.inputEmail.text)
else
LocalStorage.clearKey("UISign_RemEmailAddr")
end
UIPanelManager:ClosePanel(UIPanelDef.Tag.UIWeb3AuthHistory)
self.inputEmail.text = ""
local funCallback = self.funCallback
self.funCallback = nil
if funCallback then--取消登录 @todo 或者写到主动关闭界面的按钮操作那
funCallback(-1)
end
end
function UIWeb3AuthLogin:InitWeb3Auth()
local themeDictionary = {
primary = "#123456"
}
local web3AuthOptions = CS.Web3AuthOptions()
web3AuthOptions.whiteLabel = CS.WhiteLabelData()
web3AuthOptions.whiteLabel.name = "Legend of Arcadia"
web3AuthOptions.whiteLabel.logoLight = "https://legendofarcadia.io/img/icon/logo.png"
web3AuthOptions.whiteLabel.logoDark = "https://legendofarcadia.io/img/icon/logo.png"
web3AuthOptions.whiteLabel.defaultLanguage = "en"
web3AuthOptions.whiteLabel.dark = true
web3AuthOptions.whiteLabel.theme = themeDictionary
self.web3Auth = self.gameObject:GetComponent(typeof(CS.Web3Auth))
self.web3Auth:setOptions(web3AuthOptions)
self.web3Auth:onLogin("+", function(response)
self:OnLogin(response)
end)
end
---@param enumSelectedProvider CS.Provider
---@param selectedProvider number GetHashCode得到的数值
---@param strMail string|nil 邮件登录时的邮箱
function UIWeb3AuthLogin:NormalLogin(enumSelectedProvider, selectedProvider, strMail)
local options = CS.LoginParams()
options.loginProvider = enumSelectedProvider
self.loginProviderInfo = {
selectedProvider = selectedProvider,
}
if enumSelectedProvider == CS.Provider.EMAIL_PASSWORDLESS then
options.extraLoginOptions = CS.ExtraLoginOptions()
options.extraLoginOptions.login_hint = strMail
self.loginProviderInfo.email = strMail
end
local nWaitTime = 10
if Platform.IsEditor() or Platform.IsIos() then---编辑器下,切到验证页面时计时器不会暂停,等待时间长一点
nWaitTime = 120
end
self.DuckTimerId = Timer:DelayCall(nWaitTime, function()
self.DuckTimerId = nil
UIPanelManager:ClosePanel(UIPanelDef.Tag.UIDuckLoading)
FastTips:Show(GetStringByKey("ErrorCode_"..ErrorCode.ConnectCode.Overtime))
self.loginProviderInfo = nil
end)
UIPanelManager:OpenPanel(UIPanelDef.Tag.UIDuckLoading, UIPanelDef.LoadingFadeTime)
self.web3Auth:login(options);
end
function UIWeb3AuthLogin:OnBtnClick(nIndex)
local enumSelectedProvider = verifierList[nIndex].loginProvider
local strMail = nil
local selectedProvider = enumSelectedProvider:GetHashCode()
if enumSelectedProvider == CS.Provider.EMAIL_PASSWORDLESS then
if not UIUtil.IsEMail(self.inputEmail.text) then
Logger:Error(LoggerTag, "Error Email", self.inputEmail.text)
FastTips:Show( GetStringByKey("UILoginNFTPanel_Emailincorrect","请入邮箱为空,或邮箱格式不正确"))
return
end
strMail = self.inputEmail.text
end
---@type SdkWeb3Auth
local tSdk = SDKLogic:GetSdkInstance(AccountType.Web3Auth)
if not tSdk then
Logger:Error(LoggerTag, "OnLogin tSdk is nil")
return
end
-- 走正常登录
self:NormalLogin(enumSelectedProvider, selectedProvider, strMail)
end
-- self.loginProviderInfo
-- {
-- selectedProvider = 0,
-- email = "test@gmail.com",
-- }
-- tbLuaResponse
--{
-- "email" : "test@gmail.com",
-- "provider" : 0,
-- "refreshToken": "xxxxxxxxxxx...xxxxxxxxxxx",
-- "publicKey" : "xxxxxxxxxxx...xxxxxxxxxxx",
-- "address" : "xxxxxxxxxxx...xxxxxxxxxxx",
-- "idToken" : "xxxxxxxxxxx...xxxxxxxxxxx"
--}
function UIWeb3AuthLogin:OnSuccessLogin(tbLuaResponse)
local funCallback = self.funCallback
self.funCallback = nil
if tbLuaResponse.provider == CS.Provider.GOOGLE:GetHashCode() then
LogReport:EnterGameStep("OnGoogleLogin")
elseif tbLuaResponse.provider == CS.Provider.FACEBOOK:GetHashCode() then
LogReport:EnterGameStep("OnFacebookLogin")
elseif tbLuaResponse.provider == CS.Provider.DISCORD:GetHashCode() then
LogReport:EnterGameStep("OnDiscordLogin")
elseif tbLuaResponse.provider == CS.Provider.EMAIL_PASSWORDLESS:GetHashCode() then
LogReport:EnterGameStep("OnEmailLogin")
end
if funCallback then--成功登录
funCallback(0, cjson.encode(tbLuaResponse))
end
self:Close()
end
function UIWeb3AuthLogin:OnFailedLogin(tbLuaResponse)
if tbLuaResponse == nil or tbLuaResponse.provider == nil then
return
end
if tbLuaResponse.provider == CS.Provider.GOOGLE:GetHashCode() then
LogReport:EnterGameStep("OnGoogleLoginFailed")
Logger:Debug(LoggerTag, "OnGoogleLoginFailed")
elseif tbLuaResponse.provider == CS.Provider.FACEBOOK:GetHashCode() then
LogReport:EnterGameStep("OnFacebookLoginFailed")
Logger:Debug(LoggerTag, "OnFacebookLoginFailed")
elseif tbLuaResponse.provider == CS.Provider.DISCORD:GetHashCode() then
LogReport:EnterGameStep("OnDiscordLoginFailed")
Logger:Debug(LoggerTag, "OnDiscordLoginFailed")
elseif tbLuaResponse.provider == CS.Provider.EMAIL_PASSWORDLESS:GetHashCode() then
LogReport:EnterGameStep("OnEmailLoginFailed")
Logger:Debug(LoggerTag, "OnEmailLoginFailed")
end
end
function UIWeb3AuthLogin:OnLogin(response)
local tSdk = SDKLogic:GetSdkInstance(AccountType.Web3Auth)---@type SdkWeb3Auth
if not tSdk then
Logger:Error(LoggerTag, "OnLogin tSdk is nil")
return
end
local loginProviderInfo = self.loginProviderInfo
tSdk:OnWeb3AuthLoginRsp(response, loginProviderInfo,
function(nRet, tbLuaResponse)
if not tbLuaResponse then
self:OnFailedLogin({ provider = loginProviderInfo.selectedProvider })
Logger:Error(LoggerTag, "OnWeb3AuthLoginRsp no tbLuaResponse")
return
end
---已超时 不处理
if not self.DuckTimerId then
self:OnFailedLogin(tbLuaResponse)
return
end
UIPanelManager:ClosePanel(UIPanelDef.Tag.UIDuckLoading)
Timer:StopTimer(self.DuckTimerId)
self.DuckTimerId = nil
if nRet ~= 0 then
self:OnFailedLogin(tbLuaResponse)
Logger:Error(LoggerTag, "OnWeb3AuthLoginRsp nRet", nRet)
FastTips:Show(GetStringByKey("ErrorCode_"..nRet))
return
end
self:OnSuccessLogin(tbLuaResponse)
end
)
end
local ActivePosition = Vector2(23.5, 0)
local InactivePosition = Vector2(-23.5, 0)
function UIWeb3AuthLogin:SetRememberBtnActive(bActive, bUseTweenAnim)
if bUseTweenAnim then
self:FindUI("imgRemInactiveBg"):DOFade(bActive and 0 or 1, 0.3)
self:FindUI("imgRemember").transform:DOLocalMoveX(bActive and 23.5 or -23.5, 0.3)
else
self:SetItemAlpha("imgRemInactiveBg", bActive and 0 or 1)
self:FindUI("imgRemember").transform.localPosition = bActive and ActivePosition or InactivePosition
end
end
function UIWeb3AuthLogin:SwitchLoginPage(nLoginType)
self:SetVisible("NormalContainer", nLoginType == LoginType.Normal)
self:SetVisible("HistoryContainer", nLoginType == LoginType.History)
end
function UIWeb3AuthLogin:FmtEmailAddress(strEmail)
if strEmail == nil or strEmail == "" then
return ""
end
local strPrefix, strDomain = string.match(strEmail, "^(.-)@(.+)$")
local strTruncatedPrefix = string.sub(strPrefix, 1, 2) -- 获取前两个字符
local strTruncatedEmail = strTruncatedPrefix .. "..." .. "@" .. strDomain -- 拼接转换后的邮箱地址
return strTruncatedEmail
end
function UIWeb3AuthLogin:SetHistoryContainerUI(tbHistory)
if tbHistory == nil or not next(tbHistory) then
self:SetVisible("imgIcon", false)
self:SetText("txtEmail", "No email address")
return
end
local strIcon = AccountIcon[tbHistory.provider]
self:SetVisible("imgIcon", strIcon ~= nil)
if strIcon then
self:SetImageAsync("imgIcon", strIcon)
end
self:SetText("txtEmail", tbHistory.email) -- self:FmtEmailAddress(tbHistory.email)
end
return UIWeb3AuthLogin
console logs nothing special about web3auth