Add refresh token support with /api/auth/refresh endpoint

- RefreshToken entity added with 1-token-per-user logic.
- JWT can be renewed without full login using refresh token.
This commit is contained in:
K
2025-07-03 03:15:31 +05:30
parent 178a32f908
commit 2379d95759
6 changed files with 138 additions and 0 deletions
@@ -0,0 +1,33 @@
package com.skycrate.backend.skycrateBackend.entity;
import jakarta.persistence.*;
import java.time.Instant;
@Entity
public class RefreshToken {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, unique = true)
private String token;
@OneToOne
@JoinColumn(name = "user_id", referencedColumnName = "id")
private User user;
private Instant expiryDate;
// Getters and setters
public Long getId() { return id; }
public String getToken() { return token; }
public void setToken(String token) { this.token = token; }
public User getUser() { return user; }
public void setUser(User user) { this.user = user; }
public Instant getExpiryDate() { return expiryDate; }
public void setExpiryDate(Instant expiryDate) { this.expiryDate = expiryDate; }
}