project init
This commit is contained in:
43
apps/api/src/auth/auth.controller.ts
Normal file
43
apps/api/src/auth/auth.controller.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Get,
|
||||
Body,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { AuthService } from './auth.service';
|
||||
import { CurrentUser } from './decorators/current-user.decorator';
|
||||
import { Public } from './decorators/public.decorator';
|
||||
import { User } from '@coursecraft/database';
|
||||
import { ExchangeTokenDto } from './dto/exchange-token.dto';
|
||||
|
||||
@ApiTags('auth')
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private authService: AuthService) {}
|
||||
|
||||
@Public()
|
||||
@Post('exchange')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'Exchange Supabase token for API token' })
|
||||
async exchangeToken(@Body() dto: ExchangeTokenDto) {
|
||||
const user = await this.authService.validateSupabaseToken(dto.supabaseToken);
|
||||
return this.authService.generateTokens(user);
|
||||
}
|
||||
|
||||
@Get('me')
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get current user' })
|
||||
async getCurrentUser(@CurrentUser() user: User) {
|
||||
return {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
avatarUrl: user.avatarUrl,
|
||||
subscriptionTier: user.subscriptionTier,
|
||||
createdAt: user.createdAt,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user