This commit is contained in:
2025-07-16 16:25:16 +09:00
parent 11af12a806
commit 8135650344
34 changed files with 301 additions and 41 deletions

View File

@@ -23,10 +23,10 @@ let AuthController = class AuthController {
this.authService = authService;
}
async signup(dto) {
return this.authService.signup(dto);
return await this.authService.signup(dto);
}
async login(dto) {
return this.authService.login(dto);
return await this.authService.login(dto);
}
};
exports.AuthController = AuthController;

View File

@@ -1 +1 @@
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwD;AACxD,iDAA6C;AAC7C,kEAA8D;AAC9D,yDAA2D;AAGpD,IAAM,cAAc,GAApB,MAAM,cAAc;IACM;IAA7B,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAGnD,AAAN,KAAK,CAAC,MAAM,CAAS,GAAkB;QACnC,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;IAGK,AAAN,KAAK,CAAC,KAAK,CAAS,GAAiB;QACjC,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;CACJ,CAAA;AAZY,wCAAc;AAIjB;IADL,IAAA,aAAI,EAAC,QAAQ,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,+BAAa;;4CAEtC;AAGK;IADL,IAAA,aAAI,EAAC,OAAO,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,6BAAY;;2CAEpC;yBAXQ,cAAc;IAD1B,IAAA,mBAAU,EAAC,MAAM,CAAC;qCAE2B,0BAAW;GAD5C,cAAc,CAY1B"}
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwD;AACxD,iDAA6C;AAC7C,kEAA8D;AAC9D,yDAA2D;AAGpD,IAAM,cAAc,GAApB,MAAM,cAAc;IACM;IAA7B,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAGnD,AAAN,KAAK,CAAC,MAAM,CAAS,GAAkB;QACnC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IAGK,AAAN,KAAK,CAAC,KAAK,CAAS,GAAiB;QACjC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;CACJ,CAAA;AAZY,wCAAc;AAIjB;IADL,IAAA,aAAI,EAAC,QAAQ,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,+BAAa;;4CAEtC;AAGK;IADL,IAAA,aAAI,EAAC,OAAO,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,6BAAY;;2CAEpC;yBAXQ,cAAc;IAD1B,IAAA,mBAAU,EAAC,MAAM,CAAC;qCAE2B,0BAAW;GAD5C,cAAc,CAY1B"}

View File

@@ -14,6 +14,7 @@ const users_module_1 = require("../users/users.module");
const jwt_1 = require("@nestjs/jwt");
const config_1 = require("@nestjs/config");
const passport_1 = require("@nestjs/passport");
const jwt_stratedy_1 = require("./jwt.stratedy");
let AuthModule = class AuthModule {
};
exports.AuthModule = AuthModule;
@@ -31,10 +32,10 @@ exports.AuthModule = AuthModule = __decorate([
signOptions: {
expiresIn: configService.get('JWT_EXPIRES_IN') || '60s',
},
})
}),
})
],
providers: [auth_service_1.AuthService],
providers: [auth_service_1.AuthService, jwt_stratedy_1.JwtStrategy],
controllers: [auth_controller_1.AuthController]
})
], AuthModule);

View File

@@ -1 +1 @@
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../src/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iDAA6C;AAC7C,uDAAmD;AACnD,wDAAqD;AACrD,qCAAw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WAAW,EAAE;wBACX,SAAS,EAAE,aAAa,CAAC,GAAG,CAAS,gBAAgB,CAAC,IAAI,KAAK;qBAChE;iBACF,CAAC;aACH,CAAC;SACH;QACD,SAAS,EAAE,CAAC,0BAAW,EAAE,0BAAW,CAAC;QACrC,WAAW,EAAE,CAAC,gCAAc,CAAC;KAC9B,CAAC;GACW,UAAU,CAAG"}

View File

@@ -30,30 +30,18 @@ let AuthService = class AuthService {
return null;
}
async login(dto) {
try {
const user = await this.userService.findByName(dto.name);
if (!user)
throw new common_1.UnauthorizedException('Login failed');
const passwordCheck = await bcrypt.compare(dto.password, user.password);
if (!passwordCheck)
throw new common_1.UnauthorizedException('Login failed');
const payload = { username: user.name, sub: user.id };
return { access_token: this.jwtService.sign(payload) };
}
catch (error) {
if (error instanceof common_1.UnauthorizedException)
throw error;
throw new common_1.InternalServerErrorException('Login failed (Internal)');
}
const user = await this.userService.findByName(dto.name);
if (!user)
throw new common_1.UnauthorizedException('Login failed');
const passwordCheck = await bcrypt.compare(dto.password, user.password);
if (!passwordCheck)
throw new common_1.UnauthorizedException('Login failed');
const payload = { username: user.name, sub: user.id };
return { access_token: this.jwtService.sign(payload) };
}
async signup(dto) {
try {
const hashed = await bcrypt.hash(dto.password, 10);
return this.userService.create({ ...dto, password: hashed });
}
catch (error) {
throw new common_1.BadRequestException('Signup failed');
}
const hashed = await bcrypt.hash(dto.password, 10);
return this.userService.create({ ...dto, password: hashed });
}
};
exports.AuthService = AuthService;

View File

@@ -1 +1 @@
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAsH;AACtH,qCAAyC;AACzC,0DAAuD;AACvD,iCAAgC;AAKzB,IAAM,WAAW,GAAjB,MAAM,WAAW;IACA;IAAmC;IAAvD,YAAoB,WAAyB,EAAU,UAAsB;QAAzD,gBAAW,GAAX,WAAW,CAAc;QAAU,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;I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AAC,CAAC;QACrD,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,8BAAqB,CAAC,cAAc,CAAC,CAAC;QAE3D,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,CAAC,aAAa;YAAE,MAAM,IAAI,8BAAqB,CAAC,cAAc,CAAC,CAAC;QAEpE,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;QACtD,OAAO,EAAE,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAkB;QAC3B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACrE,CAAC;CACJ,CAAA;AA7BY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAEwB,4BAAY,EAAsB,gBAAU;GADpE,WAAW,CA6BvB"}

4
backend/dist/auth/jwt-auth.guard.d.ts vendored Executable file
View File

@@ -0,0 +1,4 @@
declare const JwtAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
export declare class JwtAuthGuard extends JwtAuthGuard_base {
}
export {};

18
backend/dist/auth/jwt-auth.guard.js vendored Executable file
View File

@@ -0,0 +1,18 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JwtAuthGuard = void 0;
const common_1 = require("@nestjs/common");
const passport_1 = require("@nestjs/passport");
let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)('jwt') {
};
exports.JwtAuthGuard = JwtAuthGuard;
exports.JwtAuthGuard = JwtAuthGuard = __decorate([
(0, common_1.Injectable)()
], JwtAuthGuard);
//# sourceMappingURL=jwt-auth.guard.js.map

1
backend/dist/auth/jwt-auth.guard.js.map vendored Executable file
View File

@@ -0,0 +1 @@
{"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../../src/auth/jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA6C;AAGtC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,IAAA,oBAAS,EAAC,KAAK,CAAC;CAAG,CAAA;AAAxC,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;GACA,YAAY,CAA4B"}

10
backend/dist/auth/jwt.stratedy.d.ts vendored Executable file
View File

@@ -0,0 +1,10 @@
import { ConfigService } from '@nestjs/config';
declare const JwtStrategy_base: new (...args: any) => any;
export declare class JwtStrategy extends JwtStrategy_base {
constructor(config: ConfigService);
validate(payload: any): Promise<{
userId: any;
username: any;
}>;
}
export {};

34
backend/dist/auth/jwt.stratedy.js vendored Executable file
View File

@@ -0,0 +1,34 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JwtStrategy = void 0;
const common_1 = require("@nestjs/common");
const passport_1 = require("@nestjs/passport");
const passport_jwt_1 = require("passport-jwt");
const config_1 = require("@nestjs/config");
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
constructor(config) {
super({
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: config.get('JWT_SECRET'),
});
}
async validate(payload) {
return { userId: payload.sub, username: payload.username };
}
};
exports.JwtStrategy = JwtStrategy;
exports.JwtStrategy = JwtStrategy = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [config_1.ConfigService])
], JwtStrategy);
//# sourceMappingURL=jwt.stratedy.js.map

1
backend/dist/auth/jwt.stratedy.js.map vendored Executable file
View File

@@ -0,0 +1 @@
{"version":3,"file":"jwt.stratedy.js","sourceRoot":"","sources":["../../src/auth/jwt.stratedy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAoD;AACpD,+CAAoD;AACpD,2CAA+C;AAGxC,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACzD,YAAY,MAAqB;QAC/B,KAAK,CAAC;YACJ,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,MAAM,CAAC,GAAG,CAAS,YAAY,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAY;QACzB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC7D,CAAC;CACF,CAAA;AAZY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAES,sBAAa;GADtB,WAAW,CAYvB"}