chore(api): update dependencies

This commit is contained in:
Julian Tölle 2020-05-02 17:17:20 +02:00
parent 05f230a7ce
commit d881a78757
37 changed files with 4804 additions and 2700 deletions

View file

@ -31,7 +31,7 @@ export class AuthController {
maxAge: 15 * 60 * 1000,
// Must be readable by SPA
httpOnly: false
httpOnly: false,
});
// Redirect User to SPA

View file

@ -14,14 +14,14 @@ import { SpotifyStrategy } from "./spotify.strategy";
JwtModule.registerAsync({
useFactory: (config: ConfigService) => ({
secret: config.get<string>("JWT_SECRET"),
signOptions: { expiresIn: config.get<string>("JWT_EXPIRATION_TIME") }
signOptions: { expiresIn: config.get<string>("JWT_EXPIRATION_TIME") },
}),
inject: [ConfigService]
inject: [ConfigService],
}),
UsersModule
UsersModule,
],
providers: [AuthService, SpotifyStrategy, JwtStrategy],
exports: [PassportModule],
controllers: [AuthController]
controllers: [AuthController],
})
export class AuthModule {}

View file

@ -6,7 +6,7 @@ describe("AuthService", () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthService]
providers: [AuthService],
}).compile();
service = module.get<AuthService>(AuthService);

View file

@ -14,7 +14,7 @@ export class AuthService {
async spotifyLogin({
accessToken,
refreshToken,
profile
profile,
}: LoginDto): Promise<User> {
const user = await this.usersService.createOrUpdate({
displayName: profile.displayName,
@ -22,8 +22,8 @@ export class AuthService {
spotify: {
id: profile.id,
accessToken,
refreshToken
}
refreshToken,
},
});
return user;
@ -33,7 +33,7 @@ export class AuthService {
const payload = {
sub: user.id,
name: user.displayName,
picture: user.photo
picture: user.photo,
};
const token = await this.jwtService.signAsync(payload);

View file

@ -1,3 +1,8 @@
import { createParamDecorator } from "@nestjs/common";
import { createParamDecorator, ExecutionContext } from "@nestjs/common";
export const ReqUser = createParamDecorator((data, req) => req.user);
export const ReqUser = createParamDecorator<void>(
(_: void, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
return request.user;
}
);

View file

@ -7,13 +7,13 @@ import { AuthService } from "./auth.service";
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(
private readonly config: ConfigService,
private readonly authService: AuthService
private readonly authService: AuthService,
config: ConfigService
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: config.get<string>("JWT_SECRET")
secretOrKey: config.get<string>("JWT_SECRET"),
});
}

View file

@ -13,13 +13,14 @@ export class SpotifyStrategy extends PassportStrategy(Strategy) {
super({
clientID: config.get<string>("SPOTIFY_CLIENT_ID"),
clientSecret: config.get<string>("SPOTIFY_CLIENT_SECRET"),
callbackURL: `${config.get<string>("BASE_DOMAIN") ||
"http://localhost:3000"}/api/v1/auth/spotify/callback`,
callbackURL: `${
config.get<string>("BASE_DOMAIN") || "http://localhost:3000"
}/api/v1/auth/spotify/callback`,
scope: [
"user-read-private",
"user-read-email",
"user-read-recently-played"
]
"user-read-recently-played",
],
});
}
@ -27,7 +28,7 @@ export class SpotifyStrategy extends PassportStrategy(Strategy) {
return await this.authService.spotifyLogin({
accessToken,
refreshToken,
profile
profile,
});
}
}