mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 01:29:31 +08:00
fix(core): error state for non early access user while signing in with email (#4467)
This commit is contained in:
@@ -3,12 +3,13 @@ import {
|
|||||||
CountDownRender,
|
CountDownRender,
|
||||||
ModalHeader,
|
ModalHeader,
|
||||||
} from '@affine/component/auth-components';
|
} from '@affine/component/auth-components';
|
||||||
import { getUserQuery } from '@affine/graphql';
|
import { type GetUserQuery, getUserQuery } from '@affine/graphql';
|
||||||
import { Trans } from '@affine/i18n';
|
import { Trans } from '@affine/i18n';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { useMutation } from '@affine/workspace/affine/gql';
|
import { useMutation } from '@affine/workspace/affine/gql';
|
||||||
import { ArrowDownBigIcon, GoogleDuotoneIcon } from '@blocksuite/icons';
|
import { ArrowDownBigIcon, GoogleDuotoneIcon } from '@blocksuite/icons';
|
||||||
import { Button } from '@toeverything/components/button';
|
import { Button } from '@toeverything/components/button';
|
||||||
|
import { GraphQLError } from 'graphql';
|
||||||
import { type FC, useState } from 'react';
|
import { type FC, useState } from 'react';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
@@ -56,7 +57,25 @@ export const SignIn: FC<AuthPanelProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
setIsValidEmail(true);
|
setIsValidEmail(true);
|
||||||
const { user } = await verifyUser({ email });
|
// 0 for no access for internal beta
|
||||||
|
let user: GetUserQuery['user'] | null | 0 = null;
|
||||||
|
await verifyUser({ email })
|
||||||
|
.then(({ user: u }) => {
|
||||||
|
user = u;
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
const e = err?.[0];
|
||||||
|
if (e instanceof GraphQLError && e.extensions?.code === 402) {
|
||||||
|
setAuthState('noAccess');
|
||||||
|
user = 0;
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (user === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
setAuthEmail(email);
|
setAuthEmail(email);
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
HttpException,
|
HttpStatus,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
Resolver,
|
Resolver,
|
||||||
} from '@nestjs/graphql';
|
} from '@nestjs/graphql';
|
||||||
import type { User } from '@prisma/client';
|
import type { User } from '@prisma/client';
|
||||||
|
import { GraphQLError } from 'graphql';
|
||||||
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
|
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
|
||||||
|
|
||||||
import { PrismaService } from '../../prisma/service';
|
import { PrismaService } from '../../prisma/service';
|
||||||
@@ -120,9 +121,14 @@ export class UserResolver {
|
|||||||
@Public()
|
@Public()
|
||||||
async user(@Args('email') email: string) {
|
async user(@Args('email') email: string) {
|
||||||
if (!(await this.users.canEarlyAccess(email))) {
|
if (!(await this.users.canEarlyAccess(email))) {
|
||||||
return new HttpException(
|
return new GraphQLError(
|
||||||
`You don't have early access permission\nVisit https://community.affine.pro/c/insider-general/ for more information`,
|
`You don't have early access permission\nVisit https://community.affine.pro/c/insider-general/ for more information`,
|
||||||
401
|
{
|
||||||
|
extensions: {
|
||||||
|
status: HttpStatus[HttpStatus.PAYMENT_REQUIRED],
|
||||||
|
code: HttpStatus.PAYMENT_REQUIRED,
|
||||||
|
},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// TODO: need to limit a user can only get another user witch is in the same workspace
|
// TODO: need to limit a user can only get another user witch is in the same workspace
|
||||||
|
|||||||
Reference in New Issue
Block a user