@automators/auth
v1.2.2
Published
A library for the implementation of Automators Auth
Readme
@automators/auth
Installation
pnpm add @automators/authUsage
Sign In
"use client";
import { signIn } from "@automators/auth";
export default async function SignInButton() {
return (
<button
onClick={() => {
// will redirect to the auth subdomain
signIn();
}}
>
Sign In
</button>
);
}Sign Out
"use client";
import { signOut } from "@automators/auth";
export default async function SignOutButton() {
return (
<button
onClick={async () => {
// will delete the session but won't redirect
await signOut();
// reload the page
window.location.reload();
}}
>
Sign Out
</button>
);
}Get Logged In User
To get the logged in user client side:
"use client";
import { fetchUser } from "@automators/auth";
import { useQuery } from "@tanstack/react-query";
export function useUser() {
return useQuery({
queryKey: ["user"],
queryFn: async () => {
const res = await fetchUser();
return res.json();
},
});
}To get the logged in user server side:
// server side
import { getUser } from "@automators/auth";
export default async function Page() {
const user = await getUser();
return (
<div>
<h1>Welcome {user.name}</h1>
</div>
);
}License
MIT
