managarten/apps-archived/news/apps/api/src/auth/auth.controller.ts
Till-JS 61d181fbc2 chore: archive inactive projects to apps-archived/
Move inactive projects out of active workspace:
- bauntown (community website)
- maerchenzauber (AI story generation)
- memoro (voice memo app)
- news (news aggregation)
- nutriphi (nutrition tracking)
- reader (reading app)
- uload (URL shortener)
- wisekeep (AI wisdom extraction)

Update CLAUDE.md documentation:
- Add presi to active projects
- Document archived projects section
- Update workspace configuration

Archived apps can be re-activated by moving back to apps/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 07:03:59 +01:00

88 lines
1.9 KiB
TypeScript

import { Controller, Post, Get, Body, Headers, UnauthorizedException } from '@nestjs/common';
import { AuthService } from './auth.service';
import { IsEmail, IsString, MinLength, IsOptional } from 'class-validator';
class SignUpDto {
@IsEmail()
email: string;
@IsString()
@MinLength(6)
password: string;
@IsOptional()
@IsString()
name?: string;
}
class SignInDto {
@IsEmail()
email: string;
@IsString()
password: string;
}
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
@Post('signup')
async signUp(@Body() body: SignUpDto) {
const result = await this.authService.signUp(body.email, body.password, body.name);
return {
user: {
id: result.user.id,
email: result.user.email,
name: result.user.name,
},
token: result.token,
};
}
@Post('signin')
async signIn(@Body() body: SignInDto) {
const result = await this.authService.signIn(body.email, body.password);
return {
user: {
id: result.user.id,
email: result.user.email,
name: result.user.name,
},
token: result.token,
};
}
@Post('signout')
async signOut(@Headers('authorization') authHeader: string) {
if (!authHeader || !authHeader.startsWith('Bearer ')) {
throw new UnauthorizedException('No token provided');
}
const token = authHeader.substring(7);
await this.authService.signOut(token);
return { success: true };
}
@Get('session')
async getSession(@Headers('authorization') authHeader: string) {
if (!authHeader || !authHeader.startsWith('Bearer ')) {
throw new UnauthorizedException('No token provided');
}
const token = authHeader.substring(7);
const session = await this.authService.getSession(token);
if (!session) {
throw new UnauthorizedException('Invalid or expired session');
}
return {
user: {
id: session.user.id,
email: session.user.email,
name: session.user.name,
},
};
}
}