update packages, using FirebaseAdminModule
This commit is contained in:
@@ -1,36 +1,12 @@
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Param, Post, Put, UseGuards } from '@nestjs/common';
|
||||
import { AuthGuard } from 'src/jwt-auth/auth.guard';
|
||||
import admin from 'src/jwt-auth/firebase-admin';
|
||||
import { KeycloakUser } from 'src/models/main.model';
|
||||
import { AuthService } from './auth.service';
|
||||
import { Body, Controller, HttpException, HttpStatus, Inject, Post } from '@nestjs/common';
|
||||
import * as admin from 'firebase-admin';
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
// @Get()
|
||||
// async getAccessToken(): Promise<any> {
|
||||
// return await this.authService.getAccessToken();
|
||||
// }
|
||||
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
// @Get('user/all')
|
||||
// async getUsers(): Promise<any> {
|
||||
// return await this.authService.getUsers();
|
||||
// }
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('users/:userid')
|
||||
async getUser(@Param('userid') userId: string): Promise<any> {
|
||||
return await this.authService.getUser(userId);
|
||||
}
|
||||
@UseGuards(AuthGuard)
|
||||
@Put('users/:userid')
|
||||
async updateKeycloakUser(@Body() keycloakUser: KeycloakUser): Promise<any> {
|
||||
return await this.authService.updateKeycloakUser(keycloakUser);
|
||||
}
|
||||
|
||||
constructor(
|
||||
@Inject('FIREBASE_ADMIN')
|
||||
private readonly firebaseAdmin: typeof admin,
|
||||
) {}
|
||||
@Post('verify-email')
|
||||
async verifyEmail(@Body('oobCode') oobCode: string, @Body('email') email: string) {
|
||||
if (!oobCode || !email) {
|
||||
@@ -39,7 +15,7 @@ export class AuthController {
|
||||
|
||||
try {
|
||||
// Schritt 1: Hole den Benutzer anhand der E-Mail-Adresse
|
||||
const userRecord = await admin.auth().getUserByEmail(email);
|
||||
const userRecord = await this.firebaseAdmin.auth().getUserByEmail(email);
|
||||
|
||||
if (userRecord.emailVerified) {
|
||||
return { message: 'Email is already verified' };
|
||||
@@ -48,7 +24,7 @@ export class AuthController {
|
||||
// Schritt 2: Aktualisiere den Benutzerstatus
|
||||
// Hinweis: Wir können den oobCode nicht serverseitig validieren.
|
||||
// Wir nehmen an, dass der oobCode korrekt ist, da er von Firebase generiert wurde.
|
||||
await admin.auth().updateUser(userRecord.uid, {
|
||||
await this.firebaseAdmin.auth().updateUser(userRecord.uid, {
|
||||
emailVerified: true,
|
||||
});
|
||||
|
||||
@@ -57,9 +33,5 @@ export class AuthController {
|
||||
throw new HttpException(error.message || 'Failed to verify email', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
// @Get('user/:userid/lastlogin') //e0811669-c7eb-4e5e-a699-e8334d5c5b01 -> aknuth
|
||||
// getLastLogin(@Param('userid') userId: string): any {
|
||||
// return this.authService.getLastLogin(userId);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user