mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-11 23:18:26 +00:00
27 lines
824 B
TypeScript
27 lines
824 B
TypeScript
import { redirect, type LoaderFunction } from "@remix-run/node";
|
|
import { authenticator } from "~/services/auth.server";
|
|
import { redirectCookie } from "./auth.google";
|
|
import { logger } from "~/services/logger.service";
|
|
import { saveSession } from "~/services/sessionStorage.server";
|
|
|
|
export let loader: LoaderFunction = async ({ request }) => {
|
|
const cookie = request.headers.get("Cookie");
|
|
const redirectValue = await redirectCookie.parse(cookie);
|
|
const redirectTo = redirectValue ?? "/";
|
|
|
|
logger.debug("auth.google.callback loader", {
|
|
redirectTo,
|
|
});
|
|
|
|
const authuser = await authenticator.authenticate("google", request);
|
|
const headers = await saveSession(request, authuser);
|
|
|
|
logger.debug("auth.google.callback authuser", {
|
|
authuser,
|
|
});
|
|
|
|
return redirect(redirectTo, {
|
|
headers,
|
|
});
|
|
};
|