209 похожих чатов

Добрейший вечерок всем в хату Как устроен этот сраный @nestjs/passport? @Injectable() export

class BearerAuthGuard extends AuthGuard('bearer') {
async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest<Request>();
const user = request.user;
return !!user;
}
}


@Injectable()
export class HttpBearerStrategy extends PassportStrategy(Strategy, 'bearer') {
constructor(private authApiService: AuthApiService) {
super();
}

async validate(token: string) {
const { user } = await this.authApiService.validateToken(token);
return user;
}
}


@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy, 'local') {
constructor(private authApiService: AuthApiService) {
super({
usernameField: 'email',
passwordField: 'hashPassword',
session: false,
});
}

async validate(email: string, password: string): Promise<UserEntity> {
return this.authApiService.searchUser(email, password);
}
}


@Injectable()
export class LocalAuthGuard extends AuthGuard('local') {
}



в модуле в providers указано использование BearerAuthGuard как глобальный


{
provide: APP_GUARD,
useClass: BearerAuthGuard,
},

есть контроллер AuthApiController в котором следующий метод для авторизации

@Post()
@HttpCode(HttpStatus.CREATED)
@ApiBody({ required: true, type: LocalAuthDao })
@UseGuards(new LocalAuthGuard())
async logIn(@Req() req: Request) {
return this.authApiService.createSession(req.user as any);
}

3 ответов

64 просмотра

"return !!user" какого черта?

Bogdan-Bednyi Автор вопроса
ilshaw
"return !!user" какого черта?

Потому что проверяю существует ли объект

Похожие вопросы

Обсуждают сегодня

Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
How are we going bro about the Raids ??
🅿️abby_FX
13
Keep saying it, it’s Trump or WW3. Iran will be emboldened if Harris wins by cheating. Israel will have to take the initiative against Iran. How has BTC faired everytime the...
Adz | Ferrum Network Product & Service Consultant @ Ferrum Network
1
------------------------------------------------------------------------------ 📢 MAJOR ANNOUNCEMENT: HSUITE ECOSYSTEM UPDATE 📢 @everyone Dear HbarSuite Community, After month...
Big Stones
3
isnt that how its called? lol
Hobbyist
34
Ok I will use this example…there has been a crazy amount of meme coins launched on solana and more recently on xrp ledger, many of these memes have found their way on to diffe...
Stevo Payne
7
Hey guys, I am a first time Staker, I'm on Chrome browser on Hex dot com, I'm using rabby wallet with my ledger nano X, but when I click the STAKE button it doesn't prompt my ...
Slug
8
VIP-391 Multichain Governance - Permissions on Ethereum, Arbitrum one and opBNB Summary If passed, following the Community proposal “Venus Upgrade - Omnichain Money Markets”...
Venus Announcements
6
Does anyone in here have a contact with EOS Labs that we could ask what they've been doing with their funding?
Bytecode360 Katoshi [1337 f4rm3r]
13
Oceaners, the journey continues with Season 7 of the Ocean Zealy Campaign, with a prize pool of 5,000 FET Join us in this season's challenges: create content, engage with our...
Stip11 | Never DM First
1
Карта сайта