-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(auth): dynamic provider server route
- Loading branch information
1 parent
975a0fb
commit b6a9715
Showing
3 changed files
with
23 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
type OAuthHandler = keyof typeof oauth | ||
|
||
export default eventHandler(async event => { | ||
const { provider } = await getValidatedRouterParams(event, z.object({ | ||
provider: z.string().min(1) | ||
}).parse) | ||
|
||
const config = getConfig() | ||
const oauthConfig = config.oauth?.[provider] | ||
const handlerName = `${provider}EventHandler` | ||
if (!Object.hasOwn(oauth, handlerName)) { | ||
throw createError({ statusCode: 400, message: 'Could not resolve this provider.' }) | ||
} | ||
|
||
return oauth[handlerName as OAuthHandler]({ | ||
config: oauthConfig as any, | ||
async onSuccess(event, { user }) { | ||
await setUserSession(event, { user }) | ||
return sendRedirect(event, '/todos') | ||
} | ||
})(event) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.