Why auth request can be accessed only by guests? #1494
-
Hi! I'm trying to create an |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
The
There is no easy way to change it. One workaround could be to register a middleware and intercept the
It just seems logical to me. Additionally it also prevents accidentally "overwriting" your I can change it, but I'm not sure that I understand the use case. Could you elaborate a little more what you are trying to do and what is the end goal (pseudo-code is also ok)? |
Beta Was this translation helpful? Give feedback.
-
My use case is the transition between "anonymous" user and an authenticated user in e-commerce app. When anonymous user logs in, I want to transfer its shopping cart & orders data to the new account. In order to do that, I need to extract the information about the current user (if it exists at all): app.OnRecordAuthRequest().Add(func(e *core.RecordAuthEvent) error {
// Extract current user.
user, _ := e.HttpContext.Get(apis.ContextAuthRecordKey).(*models.Record)
if user == nil {
return nil
}
if user.Id != e.Record.Id {
log.Printf("MOVING FROM USER %s TO USER %s\n", user.Id, e.Record.Id)
}
return nil
}) |
Beta Was this translation helpful? Give feedback.
The
/apis/collections/:collection/auth-with-password
endpoint requires the user to be "guest", aka. to NOT haveAuthorization: TOKEN
header with the request.There is no easy way to change it. One workaround could be to register a middleware and intercept the
/auth-with-password
action.It just seems logical to me. Additionally it also prevents accidentally "overwriting" your
pb.authStore
state after a successful auth call.I can change it, but I'm not sure that I understand the use case. Could you elaborate a little more what you are trying to do and what is the end goal (pseudo-code is also ok)?