-
Notifications
You must be signed in to change notification settings - Fork 484
Expand file tree
/
Copy pathSignUpHandler.java
More file actions
41 lines (35 loc) · 1.42 KB
/
SignUpHandler.java
File metadata and controls
41 lines (35 loc) · 1.42 KB
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
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import sh.ory.ApiException;
import sh.ory.api.FrontendApi;
import sh.ory.model.Session;
import java.io.IOException;
@RestController
public class SignUpHandler {
private final FrontendApi ory;
private final String baseUrl;
public SignUpHandler(FrontendApi ory, String baseUrl) {
this.ory = ory;
this.baseUrl = baseUrl;
}
@GetMapping("/signup")
public void signUp(HttpServletRequest request, HttpServletResponse response) throws IOException {
String cookieHeader = request.getHeader("Cookie");
try {
Session session = ory.toSession(null, cookieHeader, null);
if (session != null && session.getActive() != null && session.getActive()) {
// Session is valid, return session data as JSON
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(session.toString());
return;
}
} catch (ApiException e) {
// Session is invalid or doesn't exist
}
// Redirect to registration page
response.sendRedirect(baseUrl + "/self-service/registration/browser");
}
}