mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
refactor(server): auth (#5895)
Remove `next-auth` and implement our own Authorization/Authentication system from scratch.
## Server
- [x] tokens
- [x] function
- [x] encryption
- [x] AuthController
- [x] /api/auth/sign-in
- [x] /api/auth/sign-out
- [x] /api/auth/session
- [x] /api/auth/session (WE SUPPORT MULTI-ACCOUNT!)
- [x] OAuthPlugin
- [x] OAuthController
- [x] /oauth/login
- [x] /oauth/callback
- [x] Providers
- [x] Google
- [x] GitHub
## Client
- [x] useSession
- [x] cloudSignIn
- [x] cloudSignOut
## NOTE:
Tests will be adding in the future
This commit is contained in:
@@ -57,6 +57,11 @@ export enum InvoiceStatus {
|
||||
Void = 'Void',
|
||||
}
|
||||
|
||||
export enum OAuthProviderType {
|
||||
GitHub = 'GitHub',
|
||||
Google = 'Google',
|
||||
}
|
||||
|
||||
/** User permission in workspace */
|
||||
export enum Permission {
|
||||
Admin = 'Admin',
|
||||
@@ -77,6 +82,7 @@ export enum ServerDeploymentType {
|
||||
}
|
||||
|
||||
export enum ServerFeature {
|
||||
OAuth = 'OAuth',
|
||||
Payment = 'Payment',
|
||||
}
|
||||
|
||||
@@ -104,6 +110,11 @@ export enum SubscriptionStatus {
|
||||
Unpaid = 'Unpaid',
|
||||
}
|
||||
|
||||
export interface UpdateUserInput {
|
||||
/** User name */
|
||||
name: InputMaybe<Scalars['String']['input']>;
|
||||
}
|
||||
|
||||
export interface UpdateWorkspaceInput {
|
||||
id: Scalars['ID']['input'];
|
||||
/** is Public workspace */
|
||||
@@ -176,17 +187,12 @@ export type CancelSubscriptionMutation = {
|
||||
|
||||
export type ChangeEmailMutationVariables = Exact<{
|
||||
token: Scalars['String']['input'];
|
||||
email: Scalars['String']['input'];
|
||||
}>;
|
||||
|
||||
export type ChangeEmailMutation = {
|
||||
__typename?: 'Mutation';
|
||||
changeEmail: {
|
||||
__typename?: 'UserType';
|
||||
id: string;
|
||||
name: string;
|
||||
avatarUrl: string | null;
|
||||
email: string;
|
||||
};
|
||||
changeEmail: { __typename?: 'UserType'; id: string; email: string };
|
||||
};
|
||||
|
||||
export type ChangePasswordMutationVariables = Exact<{
|
||||
@@ -196,13 +202,7 @@ export type ChangePasswordMutationVariables = Exact<{
|
||||
|
||||
export type ChangePasswordMutation = {
|
||||
__typename?: 'Mutation';
|
||||
changePassword: {
|
||||
__typename?: 'UserType';
|
||||
id: string;
|
||||
name: string;
|
||||
avatarUrl: string | null;
|
||||
email: string;
|
||||
};
|
||||
changePassword: { __typename?: 'UserType'; id: string };
|
||||
};
|
||||
|
||||
export type CreateCheckoutSessionMutationVariables = Exact<{
|
||||
@@ -270,8 +270,7 @@ export type EarlyAccessUsersQuery = {
|
||||
name: string;
|
||||
email: string;
|
||||
avatarUrl: string | null;
|
||||
emailVerified: string | null;
|
||||
createdAt: string | null;
|
||||
emailVerified: boolean;
|
||||
subscription: {
|
||||
__typename?: 'UserSubscription';
|
||||
plan: SubscriptionPlan;
|
||||
@@ -301,10 +300,9 @@ export type GetCurrentUserQuery = {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
emailVerified: string | null;
|
||||
emailVerified: boolean;
|
||||
avatarUrl: string | null;
|
||||
createdAt: string | null;
|
||||
token: { __typename?: 'TokenType'; sessionToken: string | null };
|
||||
token: { __typename?: 'tokenType'; sessionToken: string | null };
|
||||
} | null;
|
||||
};
|
||||
|
||||
@@ -365,11 +363,21 @@ export type GetMembersByWorkspaceIdQuery = {
|
||||
permission: Permission;
|
||||
inviteId: string;
|
||||
accepted: boolean;
|
||||
emailVerified: string | null;
|
||||
emailVerified: boolean | null;
|
||||
}>;
|
||||
};
|
||||
};
|
||||
|
||||
export type OauthProvidersQueryVariables = Exact<{ [key: string]: never }>;
|
||||
|
||||
export type OauthProvidersQuery = {
|
||||
__typename?: 'Query';
|
||||
serverConfig: {
|
||||
__typename?: 'ServerConfigType';
|
||||
oauthProviders: Array<OAuthProviderType>;
|
||||
};
|
||||
};
|
||||
|
||||
export type GetPublicWorkspaceQueryVariables = Exact<{
|
||||
id: Scalars['String']['input'];
|
||||
}>;
|
||||
@@ -386,18 +394,14 @@ export type GetUserQueryVariables = Exact<{
|
||||
export type GetUserQuery = {
|
||||
__typename?: 'Query';
|
||||
user:
|
||||
| {
|
||||
__typename: 'LimitedUserType';
|
||||
email: string;
|
||||
hasPassword: boolean | null;
|
||||
}
|
||||
| { __typename: 'LimitedUserType'; email: string; hasPassword: boolean }
|
||||
| {
|
||||
__typename: 'UserType';
|
||||
id: string;
|
||||
name: string;
|
||||
avatarUrl: string | null;
|
||||
email: string;
|
||||
hasPassword: boolean | null;
|
||||
hasPassword: boolean;
|
||||
}
|
||||
| null;
|
||||
};
|
||||
@@ -628,7 +632,6 @@ export type RevokePublicPageMutation = {
|
||||
};
|
||||
|
||||
export type SendChangeEmailMutationVariables = Exact<{
|
||||
email: Scalars['String']['input'];
|
||||
callbackUrl: Scalars['String']['input'];
|
||||
}>;
|
||||
|
||||
@@ -638,7 +641,6 @@ export type SendChangeEmailMutation = {
|
||||
};
|
||||
|
||||
export type SendChangePasswordEmailMutationVariables = Exact<{
|
||||
email: Scalars['String']['input'];
|
||||
callbackUrl: Scalars['String']['input'];
|
||||
}>;
|
||||
|
||||
@@ -648,7 +650,6 @@ export type SendChangePasswordEmailMutation = {
|
||||
};
|
||||
|
||||
export type SendSetPasswordEmailMutationVariables = Exact<{
|
||||
email: Scalars['String']['input'];
|
||||
callbackUrl: Scalars['String']['input'];
|
||||
}>;
|
||||
|
||||
@@ -668,6 +669,15 @@ export type SendVerifyChangeEmailMutation = {
|
||||
sendVerifyChangeEmail: boolean;
|
||||
};
|
||||
|
||||
export type SendVerifyEmailMutationVariables = Exact<{
|
||||
callbackUrl: Scalars['String']['input'];
|
||||
}>;
|
||||
|
||||
export type SendVerifyEmailMutation = {
|
||||
__typename?: 'Mutation';
|
||||
sendVerifyEmail: boolean;
|
||||
};
|
||||
|
||||
export type ServerConfigQueryVariables = Exact<{ [key: string]: never }>;
|
||||
|
||||
export type ServerConfigQuery = {
|
||||
@@ -692,33 +702,6 @@ export type SetWorkspacePublicByIdMutation = {
|
||||
updateWorkspace: { __typename?: 'WorkspaceType'; id: string };
|
||||
};
|
||||
|
||||
export type SignInMutationVariables = Exact<{
|
||||
email: Scalars['String']['input'];
|
||||
password: Scalars['String']['input'];
|
||||
}>;
|
||||
|
||||
export type SignInMutation = {
|
||||
__typename?: 'Mutation';
|
||||
signIn: {
|
||||
__typename?: 'UserType';
|
||||
token: { __typename?: 'TokenType'; token: string };
|
||||
};
|
||||
};
|
||||
|
||||
export type SignUpMutationVariables = Exact<{
|
||||
name: Scalars['String']['input'];
|
||||
email: Scalars['String']['input'];
|
||||
password: Scalars['String']['input'];
|
||||
}>;
|
||||
|
||||
export type SignUpMutation = {
|
||||
__typename?: 'Mutation';
|
||||
signUp: {
|
||||
__typename?: 'UserType';
|
||||
token: { __typename?: 'TokenType'; token: string };
|
||||
};
|
||||
};
|
||||
|
||||
export type SubscriptionQueryVariables = Exact<{ [key: string]: never }>;
|
||||
|
||||
export type SubscriptionQuery = {
|
||||
@@ -755,6 +738,15 @@ export type UpdateSubscriptionMutation = {
|
||||
};
|
||||
};
|
||||
|
||||
export type UpdateUserProfileMutationVariables = Exact<{
|
||||
input: UpdateUserInput;
|
||||
}>;
|
||||
|
||||
export type UpdateUserProfileMutation = {
|
||||
__typename?: 'Mutation';
|
||||
updateProfile: { __typename?: 'UserType'; id: string; name: string };
|
||||
};
|
||||
|
||||
export type UploadAvatarMutationVariables = Exact<{
|
||||
avatar: Scalars['Upload']['input'];
|
||||
}>;
|
||||
@@ -770,6 +762,15 @@ export type UploadAvatarMutation = {
|
||||
};
|
||||
};
|
||||
|
||||
export type VerifyEmailMutationVariables = Exact<{
|
||||
token: Scalars['String']['input'];
|
||||
}>;
|
||||
|
||||
export type VerifyEmailMutation = {
|
||||
__typename?: 'Mutation';
|
||||
verifyEmail: boolean;
|
||||
};
|
||||
|
||||
export type EnabledFeaturesQueryVariables = Exact<{
|
||||
id: Scalars['String']['input'];
|
||||
}>;
|
||||
@@ -938,6 +939,11 @@ export type Queries =
|
||||
variables: GetMembersByWorkspaceIdQueryVariables;
|
||||
response: GetMembersByWorkspaceIdQuery;
|
||||
}
|
||||
| {
|
||||
name: 'oauthProvidersQuery';
|
||||
variables: OauthProvidersQueryVariables;
|
||||
response: OauthProvidersQuery;
|
||||
}
|
||||
| {
|
||||
name: 'getPublicWorkspaceQuery';
|
||||
variables: GetPublicWorkspaceQueryVariables;
|
||||
@@ -1145,31 +1151,36 @@ export type Mutations =
|
||||
variables: SendVerifyChangeEmailMutationVariables;
|
||||
response: SendVerifyChangeEmailMutation;
|
||||
}
|
||||
| {
|
||||
name: 'sendVerifyEmailMutation';
|
||||
variables: SendVerifyEmailMutationVariables;
|
||||
response: SendVerifyEmailMutation;
|
||||
}
|
||||
| {
|
||||
name: 'setWorkspacePublicByIdMutation';
|
||||
variables: SetWorkspacePublicByIdMutationVariables;
|
||||
response: SetWorkspacePublicByIdMutation;
|
||||
}
|
||||
| {
|
||||
name: 'signInMutation';
|
||||
variables: SignInMutationVariables;
|
||||
response: SignInMutation;
|
||||
}
|
||||
| {
|
||||
name: 'signUpMutation';
|
||||
variables: SignUpMutationVariables;
|
||||
response: SignUpMutation;
|
||||
}
|
||||
| {
|
||||
name: 'updateSubscriptionMutation';
|
||||
variables: UpdateSubscriptionMutationVariables;
|
||||
response: UpdateSubscriptionMutation;
|
||||
}
|
||||
| {
|
||||
name: 'updateUserProfileMutation';
|
||||
variables: UpdateUserProfileMutationVariables;
|
||||
response: UpdateUserProfileMutation;
|
||||
}
|
||||
| {
|
||||
name: 'uploadAvatarMutation';
|
||||
variables: UploadAvatarMutationVariables;
|
||||
response: UploadAvatarMutation;
|
||||
}
|
||||
| {
|
||||
name: 'verifyEmailMutation';
|
||||
variables: VerifyEmailMutationVariables;
|
||||
response: VerifyEmailMutation;
|
||||
}
|
||||
| {
|
||||
name: 'setWorkspaceExperimentalFeatureMutation';
|
||||
variables: SetWorkspaceExperimentalFeatureMutationVariables;
|
||||
|
||||
Reference in New Issue
Block a user