Skip to content

Commit

Permalink
remove most of debug messages, slice CLIENT_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleNa1000 committed Nov 1, 2024
1 parent 7cfd5f5 commit 4456e70
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 36 deletions.
4 changes: 1 addition & 3 deletions apps/api/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class AppService {
constructor(private configService: ConfigService) {}
getHello(): string {
return `Hello World! ${process.env.CLIENT_URL} ${this.configService.get<string>('CLIENT_URL')} ${process.env.BUCKET_NAME} ${this.configService.get<string>('BUCKET_NAME')}`;
return 'Hello from ESC Project Tracker API Server!';
}
}
8 changes: 0 additions & 8 deletions apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ export class AuthService {

async validateUser(token: string): Promise<IntaniaAuthResponse> {
try {
console.log(
'Nestjs, Validating user with token:',
token,
'secret: ',
this.configService.get<string>('INTANIA_AUTH_SECRET'),
);

const validatedResponse = await this.httpService.axiosRef.post(
'https://account.intania.org/api/v1/auth/app/validate',
{ token },
Expand All @@ -36,7 +29,6 @@ export class AuthService {
},
},
);
console.log('validatedResponse:', validatedResponse);

return validatedResponse.data.data as IntaniaAuthResponse;
} catch (error) {
Expand Down
7 changes: 6 additions & 1 deletion apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import * as cookieParser from 'cookie-parser';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({ credentials: true, origin: process.env.CLIENT_URL });
app.enableCors({
credentials: true,
origin: process.env.CLIENT_URL.endsWith('/')
? process.env.CLIENT_URL.slice(0, -1)
: process.env.CLIENT_URL,
});
app.use(cookieParser());
const trpc = app.get(TrpcRouter);
trpc.applyMiddleware(app);
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default function Page() {
ดำเนินการเรื่องเอกสารของคณะฯ ไม่ยุ่งยาก สะดวก รวดเร็ว
ครบจบทุกกระบวนการ มาเริ่มต้นเอกสารกัน !
</h2>
debugs: {env('INTANIA_AUTH_APP_ID')} {process.env.INTANIA_AUTH_APP_ID}
</div>
<Button
className="rounded-[80px] bg-gradient-red text-2xl font-bold px-12 py-[10px] h-16"
Expand Down
33 changes: 10 additions & 23 deletions apps/web/src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,18 @@ export async function getCookies(): Promise<Tokens> {
export async function signIn(
token: string,
): Promise<Tokens & { payload: Payload }> {
console.log(
'Nextjs server-side, Signing in with token:',
JSON.stringify({ token }),
'destination:',
process.env.NEXT_PUBLIC_API_SERVER_URL,
'destination (env):',
env('NEXT_PUBLIC_API_SERVER_URL'),
);

const data = await trpc.authRouter.signin.mutate({ token }).catch((err) => {
console.error('Nextjs server-side, signIn err:', err);
// console.log(
// 'Nextjs server-side, Signing in with token:',
// JSON.stringify({ token }),
// 'destination:',
// process.env.NEXT_PUBLIC_API_SERVER_URL,
// 'destination (env):',
// env('NEXT_PUBLIC_API_SERVER_URL'),
// );

const data = await trpc.authRouter.signin.mutate({ token }).catch(() => {
throw new Error(authErrors.signInError);
});
// const response = await fetch(
// `${env.NEXT_PUBLIC_API_SERVER_URL}/auth/signin`,
// {
// method: 'POST',
// headers: {
// Accept: 'application/json',
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify({ token }),
// },
// );
// const data: Tokens = await response.json();
const payload = await parseJwt(data.accessToken);

const cookieStore = cookies();
Expand Down

0 comments on commit 4456e70

Please sign in to comment.