Authentication
This SDK supports two interactive auth flows:
- Email/password
- SIWE (Sign-In With Ethereum)
1) Email/password flowโ
Use this when your app has a traditional email login.
A. Register (signup)โ
client, err := backup.NewBackupClient(backup.BackupClientOptions{
APIURL: "https://baas.lighthouse.storage",
})
if err != nil {
panic(err)
}
regResp, err := client.RegisterEmail("alice@example.com", "strong-password", "Alice")
if err != nil {
panic(err)
}
_ = regResp // contains userId/message
B. Verify emailโ
After registration, verify using the token from your email flow:
verifyResp, err := client.VerifyEmail(backup.EmailVerifyRequest{
Token: "<verification-token>",
})
if err != nil {
panic(err)
}
// If backend returns verifyResp.Token, SDK stores it automatically.
_ = verifyResp
C. Login with email/passwordโ
client, err := backup.NewBackupClient(backup.BackupClientOptions{
APIURL: "https://baas.lighthouse.storage",
Email: "alice@example.com",
Password: "strong-password",
})
if err != nil {
panic(err)
}
authResp, err := client.AuthenticateEmail()
if err != nil {
panic(err)
}
_ = authResp // token + user payload
2) SIWE flowโ
Use this when your app authenticates with an Ethereum wallet.
A. Construct client with wallet signerโ
Using a private key directly:
client, err := backup.NewBackupClient(backup.BackupClientOptions{
APIURL: "https://baas.lighthouse.storage",
PrivateKey: "<hex-private-key>",
})
if err != nil {
panic(err)
}
Or provide a custom signer from your wallet integration:
client, err := backup.NewBackupClient(backup.BackupClientOptions{
APIURL: "https://baas.lighthouse.storage",
Address: "0xYourWalletAddress",
SignMessage: func(message string) (string, error) {
// call your wallet sign API and return 0x-prefixed signature
return signWithWallet(message)
},
})
if err != nil {
panic(err)
}
B. Authenticate (SIWE handshake)โ
token, err := client.Authenticate()
if err != nil {
panic(err)
}
_ = token
3) Linking identities (email + wallet on one account)โ
If already authenticated, you can attach another identity:
// Link email/password identity
_, err = client.LinkIdentity(backup.LinkIdentityRequest{
Provider: "email_password",
ProviderSubject: "alice@example.com",
Password: "strong-password",
})
// Link SIWE wallet identity (lowercase address)
_, err = client.LinkIdentity(backup.LinkIdentityRequest{
Provider: "siwe",
ProviderSubject: "0xyourwalletaddress",
})