These changes include: 1. Changes to the response structure when logging in with a third-party provider, by wrapping the token in `authToken` instead of directly entering it in the return data section. 2. Adding a type to user session creation by taking only the important elements. This is to prevent data leaks because important data is in jwt.
21 lines
817 B
TypeScript
21 lines
817 B
TypeScript
import { Context } from "elysia";
|
|
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
|
import { mainErrorHandler } from "../../../helpers/error/handler";
|
|
import { googleCallbackService } from "../services/http/googleCallback.service";
|
|
import { getUserHeaderInformation } from "../../../helpers/http/userHeader/getUserHeaderInformation";
|
|
|
|
export const googleCallbackController = async (
|
|
ctx: Context & { query: { code: string; state: string; callbackURI: string } }
|
|
) => {
|
|
try {
|
|
const userHeaderInfo = getUserHeaderInformation(ctx);
|
|
|
|
const authToken = await googleCallbackService(ctx.query, userHeaderInfo);
|
|
return returnReadResponse(ctx.set, 200, "Authenticated successfully!", {
|
|
authToken,
|
|
});
|
|
} catch (error) {
|
|
return mainErrorHandler(ctx.set, error);
|
|
}
|
|
};
|