Skip to content

Instantly share code, notes, and snippets.

@abhiaiyer91
Last active September 14, 2021 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhiaiyer91/eb33dc7c57fe677eeea234802c803edc to your computer and use it in GitHub Desktop.
Save abhiaiyer91/eb33dc7c57fe677eeea234802c803edc to your computer and use it in GitHub Desktop.
import { navigate } from "gatsby-link";
import { useMoralis } from "./useMoralis";
export function useAuth() {
const { Moralis } = useMoralis();
return {
login: async () => {
try {
const user = await Moralis?.Web3.authenticate();
navigate("/");
} catch (e) {
console.error(e.message, e);
}
},
logout: async () => {
try {
await Moralis?.User.logOut();
navigate("/login");
} catch (e) {
console.error(e.message, e);
}
},
currentUser: () => {
return Moralis?.User.current();
},
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment