|
| 1 | +import type { Request, Response } from 'express'; |
1 | 2 | import { AUTH_TYPE } from '../../env-vars'; |
2 | 3 | import { getUsersFromOry, jwtConfigOry } from './ory'; |
3 | | -import { getUsersFromWorkos, jwtConfigWorkos } from './workos'; |
| 4 | +import { |
| 5 | + authenticateWithCodeWorkos, |
| 6 | + authenticateWithRefreshTokenWorkos, |
| 7 | + clearCookiesWorkos, |
| 8 | + getUsersFromWorkos, |
| 9 | + jwtConfigWorkos, |
| 10 | + loginWithPasswordWorkos, |
| 11 | + logoutSessionWorkos, |
| 12 | + resetPasswordWorkos, |
| 13 | + sendResetPasswordWorkos, |
| 14 | + signupWithPasswordWorkos, |
| 15 | + verifyEmailWorkos, |
| 16 | +} from './workos'; |
4 | 17 |
|
5 | 18 | export type UsersRequest = { |
6 | 19 | id: number; |
@@ -43,3 +56,90 @@ export const jwtConfig = () => { |
43 | 56 | throw new Error(`Unsupported auth type in jwtConfig(): ${AUTH_TYPE}`); |
44 | 57 | } |
45 | 58 | }; |
| 59 | + |
| 60 | +export const loginWithPassword = async (args: { email: string; password: string; res: Response }) => { |
| 61 | + switch (AUTH_TYPE) { |
| 62 | + case 'workos': |
| 63 | + return await loginWithPasswordWorkos(args); |
| 64 | + default: |
| 65 | + throw new Error(`Unsupported auth type in loginWithPassword(): ${AUTH_TYPE}`); |
| 66 | + } |
| 67 | +}; |
| 68 | + |
| 69 | +export const signupWithPassword = async (args: { |
| 70 | + email: string; |
| 71 | + password: string; |
| 72 | + firstName: string; |
| 73 | + lastName: string; |
| 74 | + res: Response; |
| 75 | +}) => { |
| 76 | + switch (AUTH_TYPE) { |
| 77 | + case 'workos': |
| 78 | + return await signupWithPasswordWorkos(args); |
| 79 | + default: |
| 80 | + throw new Error(`Unsupported auth type in signupWithPassword(): ${AUTH_TYPE}`); |
| 81 | + } |
| 82 | +}; |
| 83 | + |
| 84 | +export const authenticateWithCode = async (args: { code: string; res: Response }) => { |
| 85 | + switch (AUTH_TYPE) { |
| 86 | + case 'workos': |
| 87 | + return await authenticateWithCodeWorkos(args); |
| 88 | + default: |
| 89 | + throw new Error(`Unsupported auth type in authenticateWithCode(): ${AUTH_TYPE}`); |
| 90 | + } |
| 91 | +}; |
| 92 | + |
| 93 | +export const authenticateWithRefreshToken = async (args: { req: Request; res: Response }) => { |
| 94 | + switch (AUTH_TYPE) { |
| 95 | + case 'workos': |
| 96 | + return await authenticateWithRefreshTokenWorkos(args); |
| 97 | + default: |
| 98 | + throw new Error(`Unsupported auth type in authenticateWithRefreshToken(): ${AUTH_TYPE}`); |
| 99 | + } |
| 100 | +}; |
| 101 | + |
| 102 | +export const verifyEmail = async (args: { pendingAuthenticationToken: string; code: string; res: Response }) => { |
| 103 | + switch (AUTH_TYPE) { |
| 104 | + case 'workos': |
| 105 | + return await verifyEmailWorkos(args); |
| 106 | + default: |
| 107 | + throw new Error(`Unsupported auth type in verifyEmail(): ${AUTH_TYPE}`); |
| 108 | + } |
| 109 | +}; |
| 110 | + |
| 111 | +export const logoutSession = async (args: { sessionId: string; res: Response }) => { |
| 112 | + switch (AUTH_TYPE) { |
| 113 | + case 'workos': |
| 114 | + return await logoutSessionWorkos(args); |
| 115 | + default: |
| 116 | + throw new Error(`Unsupported auth type in logout(): ${AUTH_TYPE}`); |
| 117 | + } |
| 118 | +}; |
| 119 | + |
| 120 | +export const sendResetPassword = async (args: { email: string; res: Response }) => { |
| 121 | + switch (AUTH_TYPE) { |
| 122 | + case 'workos': |
| 123 | + return await sendResetPasswordWorkos(args); |
| 124 | + default: |
| 125 | + throw new Error(`Unsupported auth type in sendResetPassword(): ${AUTH_TYPE}`); |
| 126 | + } |
| 127 | +}; |
| 128 | + |
| 129 | +export const resetPassword = async (args: { token: string; password: string; res: Response }) => { |
| 130 | + switch (AUTH_TYPE) { |
| 131 | + case 'workos': |
| 132 | + return await resetPasswordWorkos(args); |
| 133 | + default: |
| 134 | + throw new Error(`Unsupported auth type in resetPassword(): ${AUTH_TYPE}`); |
| 135 | + } |
| 136 | +}; |
| 137 | + |
| 138 | +export const clearCookies = (args: { res: Response }) => { |
| 139 | + switch (AUTH_TYPE) { |
| 140 | + case 'workos': |
| 141 | + return clearCookiesWorkos(args); |
| 142 | + default: |
| 143 | + throw new Error(`Unsupported auth type in clearCookies(): ${AUTH_TYPE}`); |
| 144 | + } |
| 145 | +}; |
0 commit comments