1
1
mirror of https://github.com/usememos/memos.git synced 2024-12-21 02:01:55 +03:00

fix: check auth status

This commit is contained in:
Steven 2023-11-30 21:52:02 +08:00
parent 2437419b7f
commit fff42ebc0d
5 changed files with 405 additions and 396 deletions
api/v2
proto
web/src/store/module

View File

@ -3,16 +3,18 @@ package v2
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
)
func (s *APIV2Service) GetAuthStatus(ctx context.Context, _ *apiv2pb.GetAuthStatusRequest) (*apiv2pb.GetAuthStatusResponse, error) {
ok := true
user, err := getCurrentUser(ctx, s.Store)
if err != nil || user == nil {
ok = false
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, "failed to get current user: %v", err)
}
return &apiv2pb.GetAuthStatusResponse{
Ok: ok,
User: convertUserFromStore(user),
}, nil
}

View File

@ -2,6 +2,7 @@ syntax = "proto3";
package memos.api.v2;
import "api/v2/user_service.proto";
import "google/api/annotations.proto";
option go_package = "gen/api/v2";
@ -15,5 +16,5 @@ service AuthService {
message GetAuthStatusRequest {}
message GetAuthStatusResponse {
bool ok = 1;
User user = 1;
}

View File

@ -13,15 +13,37 @@
- [ActivityService](#memos-api-v2-ActivityService)
- [api/v2/common.proto](#api_v2_common-proto)
- [RowStatus](#memos-api-v2-RowStatus)
- [api/v2/user_service.proto](#api_v2_user_service-proto)
- [CreateUserAccessTokenRequest](#memos-api-v2-CreateUserAccessTokenRequest)
- [CreateUserAccessTokenResponse](#memos-api-v2-CreateUserAccessTokenResponse)
- [CreateUserRequest](#memos-api-v2-CreateUserRequest)
- [CreateUserResponse](#memos-api-v2-CreateUserResponse)
- [DeleteUserAccessTokenRequest](#memos-api-v2-DeleteUserAccessTokenRequest)
- [DeleteUserAccessTokenResponse](#memos-api-v2-DeleteUserAccessTokenResponse)
- [DeleteUserRequest](#memos-api-v2-DeleteUserRequest)
- [DeleteUserResponse](#memos-api-v2-DeleteUserResponse)
- [GetUserRequest](#memos-api-v2-GetUserRequest)
- [GetUserResponse](#memos-api-v2-GetUserResponse)
- [ListUserAccessTokensRequest](#memos-api-v2-ListUserAccessTokensRequest)
- [ListUserAccessTokensResponse](#memos-api-v2-ListUserAccessTokensResponse)
- [UpdateUserRequest](#memos-api-v2-UpdateUserRequest)
- [UpdateUserResponse](#memos-api-v2-UpdateUserResponse)
- [User](#memos-api-v2-User)
- [UserAccessToken](#memos-api-v2-UserAccessToken)
- [User.Role](#memos-api-v2-User-Role)
- [UserService](#memos-api-v2-UserService)
- [api/v2/auth_service.proto](#api_v2_auth_service-proto)
- [GetAuthStatusRequest](#memos-api-v2-GetAuthStatusRequest)
- [GetAuthStatusResponse](#memos-api-v2-GetAuthStatusResponse)
- [AuthService](#memos-api-v2-AuthService)
- [api/v2/common.proto](#api_v2_common-proto)
- [RowStatus](#memos-api-v2-RowStatus)
- [api/v2/inbox_service.proto](#api_v2_inbox_service-proto)
- [DeleteInboxRequest](#memos-api-v2-DeleteInboxRequest)
- [DeleteInboxResponse](#memos-api-v2-DeleteInboxResponse)
@ -88,28 +110,6 @@
- [TagService](#memos-api-v2-TagService)
- [api/v2/user_service.proto](#api_v2_user_service-proto)
- [CreateUserAccessTokenRequest](#memos-api-v2-CreateUserAccessTokenRequest)
- [CreateUserAccessTokenResponse](#memos-api-v2-CreateUserAccessTokenResponse)
- [CreateUserRequest](#memos-api-v2-CreateUserRequest)
- [CreateUserResponse](#memos-api-v2-CreateUserResponse)
- [DeleteUserAccessTokenRequest](#memos-api-v2-DeleteUserAccessTokenRequest)
- [DeleteUserAccessTokenResponse](#memos-api-v2-DeleteUserAccessTokenResponse)
- [DeleteUserRequest](#memos-api-v2-DeleteUserRequest)
- [DeleteUserResponse](#memos-api-v2-DeleteUserResponse)
- [GetUserRequest](#memos-api-v2-GetUserRequest)
- [GetUserResponse](#memos-api-v2-GetUserResponse)
- [ListUserAccessTokensRequest](#memos-api-v2-ListUserAccessTokensRequest)
- [ListUserAccessTokensResponse](#memos-api-v2-ListUserAccessTokensResponse)
- [UpdateUserRequest](#memos-api-v2-UpdateUserRequest)
- [UpdateUserResponse](#memos-api-v2-UpdateUserResponse)
- [User](#memos-api-v2-User)
- [UserAccessToken](#memos-api-v2-UserAccessToken)
- [User.Role](#memos-api-v2-User-Role)
- [UserService](#memos-api-v2-UserService)
- [api/v2/webhook_service.proto](#api_v2_webhook_service-proto)
- [CreateWebhookRequest](#memos-api-v2-CreateWebhookRequest)
- [CreateWebhookResponse](#memos-api-v2-CreateWebhookResponse)
@ -252,6 +252,327 @@
<a name="api_v2_common-proto"></a>
<p align="right"><a href="#top">Top</a></p>
## api/v2/common.proto
<a name="memos-api-v2-RowStatus"></a>
### RowStatus
| Name | Number | Description |
| ---- | ------ | ----------- |
| ROW_STATUS_UNSPECIFIED | 0 | |
| ACTIVE | 1 | |
| ARCHIVED | 2 | |
<a name="api_v2_user_service-proto"></a>
<p align="right"><a href="#top">Top</a></p>
## api/v2/user_service.proto
<a name="memos-api-v2-CreateUserAccessTokenRequest"></a>
### CreateUserAccessTokenRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
| description | [string](#string) | | |
| expires_at | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | optional | |
<a name="memos-api-v2-CreateUserAccessTokenResponse"></a>
### CreateUserAccessTokenResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| access_token | [UserAccessToken](#memos-api-v2-UserAccessToken) | | |
<a name="memos-api-v2-CreateUserRequest"></a>
### CreateUserRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
<a name="memos-api-v2-CreateUserResponse"></a>
### CreateUserResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
<a name="memos-api-v2-DeleteUserAccessTokenRequest"></a>
### DeleteUserAccessTokenRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
| access_token | [string](#string) | | access_token is the access token to delete. |
<a name="memos-api-v2-DeleteUserAccessTokenResponse"></a>
### DeleteUserAccessTokenResponse
<a name="memos-api-v2-DeleteUserRequest"></a>
### DeleteUserRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
<a name="memos-api-v2-DeleteUserResponse"></a>
### DeleteUserResponse
<a name="memos-api-v2-GetUserRequest"></a>
### GetUserRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
<a name="memos-api-v2-GetUserResponse"></a>
### GetUserResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
<a name="memos-api-v2-ListUserAccessTokensRequest"></a>
### ListUserAccessTokensRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
<a name="memos-api-v2-ListUserAccessTokensResponse"></a>
### ListUserAccessTokensResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| access_tokens | [UserAccessToken](#memos-api-v2-UserAccessToken) | repeated | |
<a name="memos-api-v2-UpdateUserRequest"></a>
### UpdateUserRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
| update_mask | [google.protobuf.FieldMask](#google-protobuf-FieldMask) | | |
<a name="memos-api-v2-UpdateUserResponse"></a>
### UpdateUserResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
<a name="memos-api-v2-User"></a>
### User
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
| id | [int32](#int32) | | |
| role | [User.Role](#memos-api-v2-User-Role) | | |
| email | [string](#string) | | |
| nickname | [string](#string) | | |
| avatar_url | [string](#string) | | |
| password | [string](#string) | | |
| row_status | [RowStatus](#memos-api-v2-RowStatus) | | |
| create_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| update_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
<a name="memos-api-v2-UserAccessToken"></a>
### UserAccessToken
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| access_token | [string](#string) | | |
| description | [string](#string) | | |
| issued_at | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| expires_at | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
<a name="memos-api-v2-User-Role"></a>
### User.Role
| Name | Number | Description |
| ---- | ------ | ----------- |
| ROLE_UNSPECIFIED | 0 | |
| HOST | 1 | |
| ADMIN | 2 | |
| USER | 3 | |
<a name="memos-api-v2-UserService"></a>
### UserService
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
| GetUser | [GetUserRequest](#memos-api-v2-GetUserRequest) | [GetUserResponse](#memos-api-v2-GetUserResponse) | GetUser gets a user by name. |
| CreateUser | [CreateUserRequest](#memos-api-v2-CreateUserRequest) | [CreateUserResponse](#memos-api-v2-CreateUserResponse) | CreateUser creates a new user. |
| UpdateUser | [UpdateUserRequest](#memos-api-v2-UpdateUserRequest) | [UpdateUserResponse](#memos-api-v2-UpdateUserResponse) | UpdateUser updates a user. |
| DeleteUser | [DeleteUserRequest](#memos-api-v2-DeleteUserRequest) | [DeleteUserResponse](#memos-api-v2-DeleteUserResponse) | DeleteUser deletes a user. |
| ListUserAccessTokens | [ListUserAccessTokensRequest](#memos-api-v2-ListUserAccessTokensRequest) | [ListUserAccessTokensResponse](#memos-api-v2-ListUserAccessTokensResponse) | ListUserAccessTokens returns a list of access tokens for a user. |
| CreateUserAccessToken | [CreateUserAccessTokenRequest](#memos-api-v2-CreateUserAccessTokenRequest) | [CreateUserAccessTokenResponse](#memos-api-v2-CreateUserAccessTokenResponse) | CreateUserAccessToken creates a new access token for a user. |
| DeleteUserAccessToken | [DeleteUserAccessTokenRequest](#memos-api-v2-DeleteUserAccessTokenRequest) | [DeleteUserAccessTokenResponse](#memos-api-v2-DeleteUserAccessTokenResponse) | DeleteUserAccessToken deletes an access token for a user. |
<a name="api_v2_auth_service-proto"></a>
<p align="right"><a href="#top">Top</a></p>
@ -277,7 +598,7 @@
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| ok | [bool](#bool) | | |
| user | [User](#memos-api-v2-User) | | |
@ -303,35 +624,6 @@
<a name="api_v2_common-proto"></a>
<p align="right"><a href="#top">Top</a></p>
## api/v2/common.proto
<a name="memos-api-v2-RowStatus"></a>
### RowStatus
| Name | Number | Description |
| ---- | ------ | ----------- |
| ROW_STATUS_UNSPECIFIED | 0 | |
| ACTIVE | 1 | |
| ARCHIVED | 2 | |
<a name="api_v2_inbox_service-proto"></a>
<p align="right"><a href="#top">Top</a></p>
@ -1142,298 +1434,6 @@
<a name="api_v2_user_service-proto"></a>
<p align="right"><a href="#top">Top</a></p>
## api/v2/user_service.proto
<a name="memos-api-v2-CreateUserAccessTokenRequest"></a>
### CreateUserAccessTokenRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
| description | [string](#string) | | |
| expires_at | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | optional | |
<a name="memos-api-v2-CreateUserAccessTokenResponse"></a>
### CreateUserAccessTokenResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| access_token | [UserAccessToken](#memos-api-v2-UserAccessToken) | | |
<a name="memos-api-v2-CreateUserRequest"></a>
### CreateUserRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
<a name="memos-api-v2-CreateUserResponse"></a>
### CreateUserResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
<a name="memos-api-v2-DeleteUserAccessTokenRequest"></a>
### DeleteUserAccessTokenRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
| access_token | [string](#string) | | access_token is the access token to delete. |
<a name="memos-api-v2-DeleteUserAccessTokenResponse"></a>
### DeleteUserAccessTokenResponse
<a name="memos-api-v2-DeleteUserRequest"></a>
### DeleteUserRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
<a name="memos-api-v2-DeleteUserResponse"></a>
### DeleteUserResponse
<a name="memos-api-v2-GetUserRequest"></a>
### GetUserRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
<a name="memos-api-v2-GetUserResponse"></a>
### GetUserResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
<a name="memos-api-v2-ListUserAccessTokensRequest"></a>
### ListUserAccessTokensRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
<a name="memos-api-v2-ListUserAccessTokensResponse"></a>
### ListUserAccessTokensResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| access_tokens | [UserAccessToken](#memos-api-v2-UserAccessToken) | repeated | |
<a name="memos-api-v2-UpdateUserRequest"></a>
### UpdateUserRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
| update_mask | [google.protobuf.FieldMask](#google-protobuf-FieldMask) | | |
<a name="memos-api-v2-UpdateUserResponse"></a>
### UpdateUserResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [User](#memos-api-v2-User) | | |
<a name="memos-api-v2-User"></a>
### User
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the user. Format: users/{username} |
| id | [int32](#int32) | | |
| role | [User.Role](#memos-api-v2-User-Role) | | |
| email | [string](#string) | | |
| nickname | [string](#string) | | |
| avatar_url | [string](#string) | | |
| password | [string](#string) | | |
| row_status | [RowStatus](#memos-api-v2-RowStatus) | | |
| create_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| update_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
<a name="memos-api-v2-UserAccessToken"></a>
### UserAccessToken
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| access_token | [string](#string) | | |
| description | [string](#string) | | |
| issued_at | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| expires_at | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
<a name="memos-api-v2-User-Role"></a>
### User.Role
| Name | Number | Description |
| ---- | ------ | ----------- |
| ROLE_UNSPECIFIED | 0 | |
| HOST | 1 | |
| ADMIN | 2 | |
| USER | 3 | |
<a name="memos-api-v2-UserService"></a>
### UserService
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
| GetUser | [GetUserRequest](#memos-api-v2-GetUserRequest) | [GetUserResponse](#memos-api-v2-GetUserResponse) | GetUser gets a user by name. |
| CreateUser | [CreateUserRequest](#memos-api-v2-CreateUserRequest) | [CreateUserResponse](#memos-api-v2-CreateUserResponse) | CreateUser creates a new user. |
| UpdateUser | [UpdateUserRequest](#memos-api-v2-UpdateUserRequest) | [UpdateUserResponse](#memos-api-v2-UpdateUserResponse) | UpdateUser updates a user. |
| DeleteUser | [DeleteUserRequest](#memos-api-v2-DeleteUserRequest) | [DeleteUserResponse](#memos-api-v2-DeleteUserResponse) | DeleteUser deletes a user. |
| ListUserAccessTokens | [ListUserAccessTokensRequest](#memos-api-v2-ListUserAccessTokensRequest) | [ListUserAccessTokensResponse](#memos-api-v2-ListUserAccessTokensResponse) | ListUserAccessTokens returns a list of access tokens for a user. |
| CreateUserAccessToken | [CreateUserAccessTokenRequest](#memos-api-v2-CreateUserAccessTokenRequest) | [CreateUserAccessTokenResponse](#memos-api-v2-CreateUserAccessTokenResponse) | CreateUserAccessToken creates a new access token for a user. |
| DeleteUserAccessToken | [DeleteUserAccessTokenRequest](#memos-api-v2-DeleteUserAccessTokenRequest) | [DeleteUserAccessTokenResponse](#memos-api-v2-DeleteUserAccessTokenResponse) | DeleteUserAccessToken deletes an access token for a user. |
<a name="api_v2_webhook_service-proto"></a>
<p align="right"><a href="#top">Top</a></p>

View File

@ -64,7 +64,7 @@ type GetAuthStatusResponse struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"`
User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
}
func (x *GetAuthStatusResponse) Reset() {
@ -99,11 +99,11 @@ func (*GetAuthStatusResponse) Descriptor() ([]byte, []int) {
return file_api_v2_auth_service_proto_rawDescGZIP(), []int{1}
}
func (x *GetAuthStatusResponse) GetOk() bool {
func (x *GetAuthStatusResponse) GetUser() *User {
if x != nil {
return x.Ok
return x.User
}
return false
return nil
}
var File_api_v2_auth_service_proto protoreflect.FileDescriptor
@ -111,33 +111,36 @@ var File_api_v2_auth_service_proto protoreflect.FileDescriptor
var file_api_v2_auth_service_proto_rawDesc = []byte{
0x0a, 0x19, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x6d, 0x65, 0x6d,
0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x16, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x41, 0x75,
0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22,
0x27, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x41, 0x75, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x01,
0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x32, 0x84, 0x01, 0x0a, 0x0b, 0x41, 0x75, 0x74,
0x68, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x75, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x41,
0x75, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x22, 0x2e, 0x6d, 0x65, 0x6d, 0x6f,
0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x75, 0x74, 0x68,
0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e,
0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x47, 0x65, 0x74,
0x41, 0x75, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x22, 0x13, 0x2f, 0x61, 0x70, 0x69,
0x2f, 0x76, 0x32, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42,
0xa8, 0x01, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70,
0x69, 0x2e, 0x76, 0x32, 0x42, 0x10, 0x41, 0x75, 0x74, 0x68, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75, 0x73, 0x65, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, 0x65,
0x6d, 0x6f, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x70,
0x69, 0x2f, 0x76, 0x32, 0x3b, 0x61, 0x70, 0x69, 0x76, 0x32, 0xa2, 0x02, 0x03, 0x4d, 0x41, 0x58,
0xaa, 0x02, 0x0c, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x70, 0x69, 0x2e, 0x56, 0x32, 0xca,
0x02, 0x0c, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x56, 0x32, 0xe2, 0x02,
0x18, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x56, 0x32, 0x5c, 0x47, 0x50,
0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0e, 0x4d, 0x65, 0x6d, 0x6f,
0x73, 0x3a, 0x3a, 0x41, 0x70, 0x69, 0x3a, 0x3a, 0x56, 0x32, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x1a, 0x19, 0x61, 0x70, 0x69, 0x2f, 0x76,
0x32, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69,
0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x22, 0x16, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x41, 0x75, 0x74, 0x68, 0x53, 0x74, 0x61,
0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x3f, 0x0a, 0x15, 0x47, 0x65,
0x74, 0x41, 0x75, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x12, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32,
0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x32, 0x84, 0x01, 0x0a, 0x0b,
0x41, 0x75, 0x74, 0x68, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x75, 0x0a, 0x0d, 0x47,
0x65, 0x74, 0x41, 0x75, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x22, 0x2e, 0x6d,
0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x47, 0x65, 0x74, 0x41,
0x75, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x23, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e,
0x47, 0x65, 0x74, 0x41, 0x75, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x22, 0x13, 0x2f,
0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x73, 0x74, 0x61, 0x74,
0x75, 0x73, 0x42, 0xa8, 0x01, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73,
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x42, 0x10, 0x41, 0x75, 0x74, 0x68, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x67, 0x69, 0x74,
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75, 0x73, 0x65, 0x6d, 0x65, 0x6d, 0x6f, 0x73,
0x2f, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e,
0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x3b, 0x61, 0x70, 0x69, 0x76, 0x32, 0xa2, 0x02, 0x03,
0x4d, 0x41, 0x58, 0xaa, 0x02, 0x0c, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x70, 0x69, 0x2e,
0x56, 0x32, 0xca, 0x02, 0x0c, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x56,
0x32, 0xe2, 0x02, 0x18, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x56, 0x32,
0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0e, 0x4d,
0x65, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x41, 0x70, 0x69, 0x3a, 0x3a, 0x56, 0x32, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -156,15 +159,17 @@ var file_api_v2_auth_service_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_api_v2_auth_service_proto_goTypes = []interface{}{
(*GetAuthStatusRequest)(nil), // 0: memos.api.v2.GetAuthStatusRequest
(*GetAuthStatusResponse)(nil), // 1: memos.api.v2.GetAuthStatusResponse
(*User)(nil), // 2: memos.api.v2.User
}
var file_api_v2_auth_service_proto_depIdxs = []int32{
0, // 0: memos.api.v2.AuthService.GetAuthStatus:input_type -> memos.api.v2.GetAuthStatusRequest
1, // 1: memos.api.v2.AuthService.GetAuthStatus:output_type -> memos.api.v2.GetAuthStatusResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
2, // 0: memos.api.v2.GetAuthStatusResponse.user:type_name -> memos.api.v2.User
0, // 1: memos.api.v2.AuthService.GetAuthStatus:input_type -> memos.api.v2.GetAuthStatusRequest
1, // 2: memos.api.v2.AuthService.GetAuthStatus:output_type -> memos.api.v2.GetAuthStatusResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_api_v2_auth_service_proto_init() }
@ -172,6 +177,7 @@ func file_api_v2_auth_service_proto_init() {
if File_api_v2_auth_service_proto != nil {
return
}
file_api_v2_user_service_proto_init()
if !protoimpl.UnsafeEnabled {
file_api_v2_auth_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetAuthStatusRequest); i {

View File

@ -78,16 +78,16 @@ const doSignOut = async () => {
const fetchCurrentUser = async () => {
const userId = localStorage.getItem("userId");
if (userId) {
const { ok } = await authServiceClient.getAuthStatus({});
if (!ok) {
const { user } = await authServiceClient.getAuthStatus({});
if (!user) {
localStorage.removeItem("userId");
return;
}
const { data } = await api.getUserById(Number(userId));
const user = convertResponseModelUser(data);
if (user) {
store.dispatch(setUser(user));
return user;
const userMessage = convertResponseModelUser(data);
if (userMessage) {
store.dispatch(setUser(userMessage));
return userMessage;
}
}
};