feat(gateway): confirmEmailLink RPC + language on the email request + profile event
Add the confirm-link edge method (auth.email.confirm_link): a new EmailConfirmLinkRequest/Result fbs table, the transcode const + handler + encoder, and the backend-client call to the existing /sessions/email/confirm-link endpoint — it rides Execute under the existing service prefix, so no proto/Caddy change. Add a language field to EmailRequestRequest and forward it (the backend already seeds it). Add the NotifyProfile sub-kind + notify.ProfileChanged, published by the confirm-link handler on a successful link so an in-app session re-fetches its profile when the email was confirmed in another browser. Regenerated fbs bindings (Go + TS).
This commit is contained in:
@@ -276,9 +276,9 @@ func (c *Client) GuestAuth(ctx context.Context, browserTz string) (SessionResp,
|
||||
// EmailRequest asks the backend to mail a login code, provisioning the account on
|
||||
// first contact; browserTz (the client's detected "±HH:MM" UTC offset) seeds the new
|
||||
// account's time zone, since the email account is created here, not at login.
|
||||
func (c *Client) EmailRequest(ctx context.Context, email, browserTz string) error {
|
||||
func (c *Client) EmailRequest(ctx context.Context, email, browserTz, language string) error {
|
||||
return c.do(ctx, http.MethodPost, "/api/v1/internal/sessions/email/request", "", "",
|
||||
map[string]string{"email": email, "browser_tz": browserTz}, nil)
|
||||
map[string]string{"email": email, "browser_tz": browserTz, "language": language}, nil)
|
||||
}
|
||||
|
||||
// EmailLogin verifies a login code and mints a session.
|
||||
@@ -289,6 +289,23 @@ func (c *Client) EmailLogin(ctx context.Context, email, code string) (SessionRes
|
||||
return out, err
|
||||
}
|
||||
|
||||
// ConfirmLinkResp is the backend's outcome of a one-tap deeplink confirmation: for a
|
||||
// login Session carries the minted credential; for a link Status is "confirmed" or
|
||||
// "merge_required".
|
||||
type ConfirmLinkResp struct {
|
||||
Purpose string `json:"purpose"`
|
||||
Status string `json:"status"`
|
||||
Session *SessionResp `json:"session,omitempty"`
|
||||
}
|
||||
|
||||
// EmailConfirmLink verifies a one-tap deeplink token; the token is the authorization.
|
||||
func (c *Client) EmailConfirmLink(ctx context.Context, token string) (ConfirmLinkResp, error) {
|
||||
var out ConfirmLinkResp
|
||||
err := c.do(ctx, http.MethodPost, "/api/v1/internal/sessions/email/confirm-link", "", "",
|
||||
map[string]string{"token": token}, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// ResolveSession maps a token to its account id and guest flag (gateway
|
||||
// session-cache miss). The guest flag lets the edge gate guest-forbidden ops.
|
||||
func (c *Client) ResolveSession(ctx context.Context, token string) (string, bool, error) {
|
||||
|
||||
@@ -37,6 +37,35 @@ func encodeAck(ok bool) []byte {
|
||||
return b.FinishedBytes()
|
||||
}
|
||||
|
||||
// encodeConfirmLinkResult builds an EmailConfirmLinkResult payload, embedding the
|
||||
// minted Session for a login. All strings and the nested Session table are built
|
||||
// before the result table is opened.
|
||||
func encodeConfirmLinkResult(r backendclient.ConfirmLinkResp) []byte {
|
||||
b := flatbuffers.NewBuilder(160)
|
||||
purpose := b.CreateString(r.Purpose)
|
||||
status := b.CreateString(r.Status)
|
||||
var session flatbuffers.UOffsetT
|
||||
if r.Session != nil {
|
||||
token := b.CreateString(r.Session.Token)
|
||||
uid := b.CreateString(r.Session.UserID)
|
||||
name := b.CreateString(r.Session.DisplayName)
|
||||
fb.SessionStart(b)
|
||||
fb.SessionAddToken(b, token)
|
||||
fb.SessionAddUserId(b, uid)
|
||||
fb.SessionAddIsGuest(b, r.Session.IsGuest)
|
||||
fb.SessionAddDisplayName(b, name)
|
||||
session = fb.SessionEnd(b)
|
||||
}
|
||||
fb.EmailConfirmLinkResultStart(b)
|
||||
fb.EmailConfirmLinkResultAddPurpose(b, purpose)
|
||||
fb.EmailConfirmLinkResultAddStatus(b, status)
|
||||
if r.Session != nil {
|
||||
fb.EmailConfirmLinkResultAddSession(b, session)
|
||||
}
|
||||
b.Finish(fb.EmailConfirmLinkResultEnd(b))
|
||||
return b.FinishedBytes()
|
||||
}
|
||||
|
||||
// encodeProfile builds a Profile payload, including the advertising-banner block
|
||||
// when the backend marked the viewer eligible.
|
||||
func encodeProfile(p backendclient.ProfileResp) []byte {
|
||||
|
||||
@@ -19,37 +19,38 @@ import (
|
||||
|
||||
// Message types in the vertical slice.
|
||||
const (
|
||||
MsgAuthTelegram = "auth.telegram"
|
||||
MsgAuthVK = "auth.vk"
|
||||
MsgAuthGuest = "auth.guest"
|
||||
MsgAuthEmailReq = "auth.email.request"
|
||||
MsgAuthEmailLogin = "auth.email.login"
|
||||
MsgProfileGet = "profile.get"
|
||||
MsgBlockStatus = "account.block_status"
|
||||
MsgGameSubmitPlay = "game.submit_play"
|
||||
MsgGameState = "game.state"
|
||||
MsgLobbyEnqueue = "lobby.enqueue"
|
||||
MsgLobbyCancel = "lobby.cancel"
|
||||
MsgLobbyPoll = "lobby.poll"
|
||||
MsgChatPost = "chat.post"
|
||||
MsgGamesList = "games.list"
|
||||
MsgGamePass = "game.pass"
|
||||
MsgGameExchange = "game.exchange"
|
||||
MsgGameResign = "game.resign"
|
||||
MsgGameHint = "game.hint"
|
||||
MsgGameEvaluate = "game.evaluate"
|
||||
MsgGameCheckWord = "game.check_word"
|
||||
MsgGameComplaint = "game.complaint"
|
||||
MsgGameHistory = "game.history"
|
||||
MsgChatList = "chat.list"
|
||||
MsgChatNudge = "chat.nudge"
|
||||
MsgChatRead = "chat.read"
|
||||
MsgDraftGet = "draft.get"
|
||||
MsgDraftSave = "draft.save"
|
||||
MsgGameHide = "game.hide"
|
||||
MsgFeedbackSubmit = "feedback.submit"
|
||||
MsgFeedbackGet = "feedback.get"
|
||||
MsgFeedbackUnread = "feedback.unread"
|
||||
MsgAuthTelegram = "auth.telegram"
|
||||
MsgAuthVK = "auth.vk"
|
||||
MsgAuthGuest = "auth.guest"
|
||||
MsgAuthEmailReq = "auth.email.request"
|
||||
MsgAuthEmailLogin = "auth.email.login"
|
||||
MsgAuthEmailConfirmLink = "auth.email.confirm_link"
|
||||
MsgProfileGet = "profile.get"
|
||||
MsgBlockStatus = "account.block_status"
|
||||
MsgGameSubmitPlay = "game.submit_play"
|
||||
MsgGameState = "game.state"
|
||||
MsgLobbyEnqueue = "lobby.enqueue"
|
||||
MsgLobbyCancel = "lobby.cancel"
|
||||
MsgLobbyPoll = "lobby.poll"
|
||||
MsgChatPost = "chat.post"
|
||||
MsgGamesList = "games.list"
|
||||
MsgGamePass = "game.pass"
|
||||
MsgGameExchange = "game.exchange"
|
||||
MsgGameResign = "game.resign"
|
||||
MsgGameHint = "game.hint"
|
||||
MsgGameEvaluate = "game.evaluate"
|
||||
MsgGameCheckWord = "game.check_word"
|
||||
MsgGameComplaint = "game.complaint"
|
||||
MsgGameHistory = "game.history"
|
||||
MsgChatList = "chat.list"
|
||||
MsgChatNudge = "chat.nudge"
|
||||
MsgChatRead = "chat.read"
|
||||
MsgDraftGet = "draft.get"
|
||||
MsgDraftSave = "draft.save"
|
||||
MsgGameHide = "game.hide"
|
||||
MsgFeedbackSubmit = "feedback.submit"
|
||||
MsgFeedbackGet = "feedback.get"
|
||||
MsgFeedbackUnread = "feedback.unread"
|
||||
)
|
||||
|
||||
// Request is one decoded Execute call.
|
||||
@@ -101,6 +102,7 @@ func NewRegistry(backend *backendclient.Client, tg TelegramValidator, opts ...Op
|
||||
r.ops[MsgAuthGuest] = Op{Handler: authGuestHandler(backend)}
|
||||
r.ops[MsgAuthEmailReq] = Op{Handler: authEmailRequestHandler(backend), Email: true}
|
||||
r.ops[MsgAuthEmailLogin] = Op{Handler: authEmailLoginHandler(backend), Email: true}
|
||||
r.ops[MsgAuthEmailConfirmLink] = Op{Handler: authEmailConfirmLinkHandler(backend)}
|
||||
r.ops[MsgProfileGet] = Op{Handler: profileHandler(backend), Auth: true}
|
||||
r.ops[MsgBlockStatus] = Op{Handler: blockStatusHandler(backend), Auth: true}
|
||||
r.ops[MsgGameSubmitPlay] = Op{Handler: submitPlayHandler(backend), Auth: true}
|
||||
@@ -238,7 +240,7 @@ func authGuestHandler(backend *backendclient.Client) Handler {
|
||||
func authEmailRequestHandler(backend *backendclient.Client) Handler {
|
||||
return func(ctx context.Context, req Request) ([]byte, error) {
|
||||
in := fb.GetRootAsEmailRequestRequest(req.Payload, 0)
|
||||
if err := backend.EmailRequest(ctx, string(in.Email()), string(in.BrowserTz())); err != nil {
|
||||
if err := backend.EmailRequest(ctx, string(in.Email()), string(in.BrowserTz()), string(in.Language())); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return encodeAck(true), nil
|
||||
@@ -256,6 +258,17 @@ func authEmailLoginHandler(backend *backendclient.Client) Handler {
|
||||
}
|
||||
}
|
||||
|
||||
func authEmailConfirmLinkHandler(backend *backendclient.Client) Handler {
|
||||
return func(ctx context.Context, req Request) ([]byte, error) {
|
||||
in := fb.GetRootAsEmailConfirmLinkRequest(req.Payload, 0)
|
||||
res, err := backend.EmailConfirmLink(ctx, string(in.Token()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return encodeConfirmLinkResult(res), nil
|
||||
}
|
||||
}
|
||||
|
||||
func profileHandler(backend *backendclient.Client) Handler {
|
||||
return func(ctx context.Context, req Request) ([]byte, error) {
|
||||
p, err := backend.Profile(ctx, req.UserID)
|
||||
|
||||
Reference in New Issue
Block a user