chore(server): add log to early access redirect (#4235)
This commit is contained in:
@@ -4,6 +4,7 @@ import { PrismaAdapter } from '@auth/prisma-adapter';
|
|||||||
import { BadRequestException, FactoryProvider, Logger } from '@nestjs/common';
|
import { BadRequestException, FactoryProvider, Logger } from '@nestjs/common';
|
||||||
import { verify } from '@node-rs/argon2';
|
import { verify } from '@node-rs/argon2';
|
||||||
import { Algorithm, sign, verify as jwtVerify } from '@node-rs/jsonwebtoken';
|
import { Algorithm, sign, verify as jwtVerify } from '@node-rs/jsonwebtoken';
|
||||||
|
import { assign, omit } from 'lodash-es';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import { NextAuthOptions } from 'next-auth';
|
import { NextAuthOptions } from 'next-auth';
|
||||||
import Credentials from 'next-auth/providers/credentials';
|
import Credentials from 'next-auth/providers/credentials';
|
||||||
@@ -123,8 +124,24 @@ export const NextAuthOptionsProvider: FactoryProvider<NextAuthOptions> = {
|
|||||||
session: {
|
session: {
|
||||||
strategy: config.node.prod ? 'database' : 'jwt',
|
strategy: config.node.prod ? 'database' : 'jwt',
|
||||||
},
|
},
|
||||||
// @ts-expect-error Third part library type mismatch
|
logger: {
|
||||||
logger: console,
|
debug(code, metadata) {
|
||||||
|
logger.debug(`${code}: ${JSON.stringify(metadata)}`);
|
||||||
|
},
|
||||||
|
error(code, metadata) {
|
||||||
|
if (metadata instanceof Error) {
|
||||||
|
// @ts-expect-error assign code to error
|
||||||
|
metadata.code = code;
|
||||||
|
logger.error(metadata);
|
||||||
|
} else if (metadata.error instanceof Error) {
|
||||||
|
assign(metadata.error, omit(metadata, 'error'), { code });
|
||||||
|
logger.error(metadata.error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
warn(code) {
|
||||||
|
logger.warn(code);
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
nextAuthOptions.providers.push(
|
nextAuthOptions.providers.push(
|
||||||
|
|||||||
@@ -131,12 +131,13 @@ export class NextAuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (redirect?.endsWith('api/auth/error?error=AccessDenied')) {
|
if (redirect?.endsWith('api/auth/error?error=AccessDenied')) {
|
||||||
|
this.logger.log('Early access redirect headers ', req.headers);
|
||||||
|
this.metrics.authFailCounter(1, {
|
||||||
|
reason: 'no_early_access_permission',
|
||||||
|
});
|
||||||
if (!req.headers?.referer) {
|
if (!req.headers?.referer) {
|
||||||
res.redirect('https://community.affine.pro/c/insider-general/');
|
res.redirect('https://community.affine.pro/c/insider-general/');
|
||||||
} else {
|
} else {
|
||||||
this.metrics.authFailCounter(1, {
|
|
||||||
reason: 'no_early_access_permission',
|
|
||||||
});
|
|
||||||
res.status(403);
|
res.status(403);
|
||||||
res.json({
|
res.json({
|
||||||
url: 'https://community.affine.pro/c/insider-general/',
|
url: 'https://community.affine.pro/c/insider-general/',
|
||||||
|
|||||||
Reference in New Issue
Block a user