Compare commits

..
5 Commits
Author SHA1 Message Date
Ivan Rezchikov af2358811a fix: ratelimiter fixed
Build and Deploy / lint-frontend (push) Canceled after 0s
Build and Deploy / build-backend (push) Canceled after 0s
Build and Deploy / build-frontend (push) Canceled after 0s
Build and Deploy / deploy (push) Canceled after 0s
Build and Deploy / test-backend (push) Canceled after 10s
2026-09-18 16:02:48 +03:00
Ivan Rezchikov 63badb0857 fix: oauth flow
Build and Deploy / test-backend (push) Successful in 1m5s
Build and Deploy / lint-frontend (push) Successful in 1m28s
Build and Deploy / build-backend (push) Successful in 3s
Build and Deploy / build-frontend (push) Successful in 41s
Build and Deploy / deploy (push) Successful in 5s
2026-09-17 23:50:36 +03:00
Ivan Rezchikov 2597e5b352 fix: fixed redirecting
Build and Deploy / test-backend (push) Successful in 1m15s
Build and Deploy / lint-frontend (push) Successful in 1m13s
Build and Deploy / build-backend (push) Successful in 50s
Build and Deploy / build-frontend (push) Successful in 40s
Build and Deploy / deploy (push) Successful in 6s
2026-09-17 13:12:54 +03:00
Ivan Rezchikov 6347e108fe fix: proxy fixed
Build and Deploy / test-backend (push) Successful in 1m31s
Build and Deploy / lint-frontend (push) Successful in 1m54s
Build and Deploy / build-backend (push) Successful in 7s
Build and Deploy / build-frontend (push) Successful in 1m0s
Build and Deploy / deploy (push) Successful in 8s
2026-09-16 17:40:25 +03:00
Ivan Rezchikov c05bdaf679 ci/cd: test
Build and Deploy / test-backend (push) Successful in 56s
Build and Deploy / lint-frontend (push) Successful in 1m26s
Build and Deploy / build-backend (push) Successful in 5s
Build and Deploy / build-frontend (push) Successful in 9s
Build and Deploy / deploy (push) Successful in 4s
2026-09-15 19:36:41 +03:00
5 changed files with 35 additions and 10 deletions
+6
View File
@@ -108,6 +108,12 @@ jobs:
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -p 1650 -H "${{ vars.DEPLOY_HOST }}" >> ~/.ssh/known_hosts
- name: Verify SSH key
run: |
ls -la ~/.ssh/deploy_key
head -1 ~/.ssh/deploy_key
tail -1 ~/.ssh/deploy_key
- name: Build .env for remote
run: |
cat > .env <<EOF
@@ -32,7 +32,7 @@ func (h *OAuthHandler) Authorize(c *gin.Context) {
return
}
c.Redirect(http.StatusFound, h.frontendURL+"/oauth?session="+token)
c.Redirect(http.StatusFound, h.frontendURL+"/login?session="+token)
}
func (h *OAuthHandler) GetSession(c *gin.Context) {
@@ -66,23 +66,34 @@ func (r *RateLimiter) Allow(ctx context.Context, key string, cfg RateLimitConfig
}
}
pipe := r.redis.Pipeline()
incrCmd := pipe.Incr(ctx, counterKey)
pipe.Expire(ctx, counterKey, cfg.Window)
if _, err := pipe.Exec(ctx); err != nil {
// Fixed-window counter: only the request that brings the counter to 1
// sets the TTL, so a burst never extends the window and the counter is
// guaranteed to reset after cfg.Window even under sustained traffic.
count64, err := r.redis.Incr(ctx, counterKey).Result()
if err != nil {
return false, 0, fmt.Errorf("rate limiter: %w", err)
}
if count64 == 1 {
if err := r.redis.Expire(ctx, counterKey, cfg.Window).Err(); err != nil {
return false, 0, fmt.Errorf("rate limiter: %w", err)
}
}
count := int(incrCmd.Val())
remaining := max(cfg.Max-count, 0)
count := int(count64)
if count > cfg.Max {
if cfg.BlockFor > 0 {
_ = r.redis.Set(ctx, blockKey, 1, cfg.BlockFor).Err()
// Reset the counter when blocking so that once the block expires
// the client is not instantly re-blocked by the stale count.
_ = r.redis.Del(ctx, counterKey).Err()
if err := r.redis.Set(ctx, blockKey, 1, cfg.BlockFor).Err(); err != nil {
return false, 0, fmt.Errorf("rate limiter: %w", err)
}
}
return false, 0, nil
}
remaining := max(cfg.Max-count, 0)
return true, remaining, nil
}
+9 -1
View File
@@ -11,8 +11,11 @@ export async function proxy(request: NextRequest) {
if (hasRefreshToken && session && pathname === "/login") {
const accessToken = request.cookies.get("access_token")?.value;
if (!accessToken) {
return NextResponse.next();
}
try {
await fetch(`${process.env.KOTOSOFT_ID_API_URL}/oauth/session/attach`, {
const res = await fetch(`${process.env.KOTOSOFT_ID_API_URL}/oauth/session/attach`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -20,6 +23,11 @@ export async function proxy(request: NextRequest) {
},
body: JSON.stringify({ session }),
});
if (!res.ok) throw new Error("attach failed");
const data = await res.json().catch(() => null);
if (data?.redirect_url) {
return NextResponse.redirect(new URL(data.redirect_url));
}
} catch (error) {
console.error("Failed to attach session:", error);
return NextResponse.redirect(new URL("/callback/error", request.url));
File diff suppressed because one or more lines are too long