Auth flow for signin and signout now preserves the path sent

This commit is contained in:
Atridad Lahiji 2023-05-30 22:16:33 -06:00
parent d57079030f
commit b4b845f5b8
No known key found for this signature in database
4 changed files with 7 additions and 4 deletions

View file

@ -68,7 +68,9 @@ const Navbar: React.FC<NavbarProps> = ({ title }) => {
</li> </li>
)} )}
<li> <li>
<a onClick={() => void signOut()}>Sign Out</a> <a onClick={() => void signOut({ callbackUrl: "/" })}>
Sign Out
</a>
</li> </li>
</ul> </ul>
</div> </div>

View file

@ -18,7 +18,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
if (!session) { if (!session) {
return { return {
redirect: { redirect: {
destination: "/", destination: `/api/auth/signin?callbackUrl=${ctx.resolvedUrl}`,
permanent: false, permanent: false,
}, },
}; };

View file

@ -37,7 +37,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
if (!session) { if (!session) {
return { return {
redirect: { redirect: {
destination: "/", destination: `/api/auth/signin?callbackUrl=${ctx.resolvedUrl}`,
permanent: false, permanent: false,
}, },
}; };

View file

@ -12,6 +12,7 @@ import { prisma } from "~/server/db";
import type { Role } from "~/utils/types"; import type { Role } from "~/utils/types";
import { sendMail } from "fms-ts"; import { sendMail } from "fms-ts";
import { cacheClient, deleteFromCache } from "redicache-ts"; import { cacheClient, deleteFromCache } from "redicache-ts";
import { redirect } from "next/navigation";
const client = cacheClient(env.REDIS_URL); const client = cacheClient(env.REDIS_URL);
@ -75,7 +76,7 @@ export const authOptions: NextAuthOptions = {
async signIn({}) { async signIn({}) {
await deleteFromCache(client, env.APP_ENV, `kv_userlist_admin`); await deleteFromCache(client, env.APP_ENV, `kv_userlist_admin`);
}, },
async signOut({}) { async signOut() {
await deleteFromCache(client, env.APP_ENV, `kv_userlist_admin`); await deleteFromCache(client, env.APP_ENV, `kv_userlist_admin`);
}, },
}, },