-
Notifications
You must be signed in to change notification settings - Fork 27
/
settings_action_end.go
49 lines (38 loc) · 1.29 KB
/
settings_action_end.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package nodes
import (
"errors"
"github.com/authgear/authgear-server/pkg/lib/interaction"
"github.com/authgear/authgear-server/pkg/lib/oauth/oauthsession"
)
func init() {
interaction.RegisterNode(&NodeSettingsActionEnd{})
}
type EdgeSettingsActionEnd struct{}
func (e *EdgeSettingsActionEnd) Instantiate(ctx *interaction.Context, graph *interaction.Graph, input interface{}) (interaction.Node, error) {
return &NodeSettingsActionEnd{}, nil
}
type NodeSettingsActionEnd struct{}
func (n *NodeSettingsActionEnd) Prepare(ctx *interaction.Context, graph *interaction.Graph) error {
return nil
}
func (n *NodeSettingsActionEnd) GetEffects() ([]interaction.Effect, error) {
return []interaction.Effect{
interaction.EffectOnCommit(func(ctx *interaction.Context, graph *interaction.Graph, nodeIndex int) error {
entry, err := ctx.OAuthSessions.Get(ctx.OAuthSessionID)
if errors.Is(err, oauthsession.ErrNotFound) {
return nil
} else if err != nil {
return err
}
entry.T.SettingsActionResult = oauthsession.NewSettingsActionResult()
err = ctx.OAuthSessions.Save(entry)
if err != nil {
return err
}
return nil
}),
}, nil
}
func (n *NodeSettingsActionEnd) DeriveEdges(graph *interaction.Graph) ([]interaction.Edge, error) {
return graph.Intent.DeriveEdgesForNode(graph, n)
}