Skip to content

Commit

Permalink
fix: remove fired codes
Browse files Browse the repository at this point in the history
  • Loading branch information
whatwewant committed Oct 31, 2023
1 parent 8d263c8 commit 1c07743
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
50 changes: 0 additions & 50 deletions api/v1/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ func (s *APIV1Service) SignIn(c echo.Context) error {
if err := s.UpsertAccessTokenToStore(ctx, user, accessToken); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("failed to upsert access token, err: %s", err)).SetInternal(err)
}
if err := s.CreateAuthSignInActivity(c, user); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
}
cookieExp := time.Now().Add(auth.CookieExpDuration)
setTokenCookie(c, auth.AccessTokenCookieName, accessToken, cookieExp)
userMessage := convertUserFromStore(user)
Expand Down Expand Up @@ -241,9 +238,6 @@ func (s *APIV1Service) SignInSSO(c echo.Context) error {
if err := s.UpsertAccessTokenToStore(ctx, user, accessToken); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("failed to upsert access token, err: %s", err)).SetInternal(err)
}
if err := s.CreateAuthSignInActivity(c, user); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
}
cookieExp := time.Now().Add(auth.CookieExpDuration)
setTokenCookie(c, auth.AccessTokenCookieName, accessToken, cookieExp)
userMessage := convertUserFromStore(user)
Expand Down Expand Up @@ -396,50 +390,6 @@ func (s *APIV1Service) UpsertAccessTokenToStore(ctx context.Context, user *store
return nil
}

func (s *APIV1Service) CreateAuthSignInActivity(c echo.Context, user *store.User) error {
ctx := c.Request().Context()
payload := ActivityUserAuthSignInPayload{
UserID: user.ID,
IP: echo.ExtractIPFromRealIPHeader()(c.Request()),
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return errors.Wrap(err, "failed to marshal activity payload")
}
activity, err := s.Store.CreateActivity(ctx, &store.Activity{
CreatorID: user.ID,
Type: string(ActivityUserAuthSignIn),
Level: string(ActivityInfo),
Payload: string(payloadBytes),
})
if err != nil || activity == nil {
return errors.Wrap(err, "failed to create activity")
}
return err
}

func (s *APIV1Service) createAuthSignUpActivity(c echo.Context, user *store.User) error {
ctx := c.Request().Context()
payload := ActivityUserAuthSignUpPayload{
Username: user.Username,
IP: echo.ExtractIPFromRealIPHeader()(c.Request()),
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return errors.Wrap(err, "failed to marshal activity payload")
}
activity, err := s.Store.CreateActivity(ctx, &store.Activity{
CreatorID: user.ID,
Type: string(ActivityUserAuthSignUp),
Level: string(ActivityInfo),
Payload: string(payloadBytes),
})
if err != nil || activity == nil {
return errors.Wrap(err, "failed to create activity")
}
return err
}

// removeAccessTokenAndCookies removes the jwt token from the cookies.
func removeAccessTokenAndCookies(c echo.Context) {
cookieExp := time.Now().Add(-1 * time.Hour)
Expand Down
3 changes: 0 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
if err := s.apiV1Service.UpsertAccessTokenToStore(ctx, user, accessToken); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("failed to upsert access token, err: %s", err)).SetInternal(err)
}
if err := s.apiV1Service.CreateAuthSignInActivity(c, user); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
}
cookieExp := time.Now().Add(auth.CookieExpDuration)

// setTokenCookie sets the token to the cookie.
Expand Down

0 comments on commit 1c07743

Please sign in to comment.