backend: add example of custom auth resolver

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-03-18 14:17:11 +01:00
parent f181c8157d
commit 9990055aa3
+12 -1
View File
@@ -35,7 +35,18 @@ export default async function createPlugin(
...defaultAuthProviderFactories,
google: providers.google.create({
signIn: {
resolver: providers.google.resolvers.byEmailLocalPart(),
resolver({ profile }, ctx) {
if (!profile.email) {
throw new Error(
'Login failed, user profile does not contain an email',
);
}
return ctx.signInWithCatalogUser({
entityRef: {
name: profile.email.split('@')[0],
},
});
},
},
}),
},