Skip to content

Commit

Permalink
feat(wabe): add authentication methods
Browse files Browse the repository at this point in the history
  • Loading branch information
coratgerl committed Jan 28, 2025
1 parent efe46a5 commit 2789dfd
Show file tree
Hide file tree
Showing 11 changed files with 526 additions and 13 deletions.
17 changes: 11 additions & 6 deletions packages/wabe-documentation/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,17 @@ export default defineConfig({
text: 'Authentication',
items: [
{
text: 'Sign In / Up',
text: 'Sign In / Up / Out',
link: '/config/authentication/interact',
},
{
text: 'Default auth methods',
link: '/config/authentication/defaultMethods',
},
{
text: 'Social login (OAuth)',
link: '/config/authentication/oauth',
},
{
text: 'Reset password',
link: '/config/authentication/resetPassword',
Expand All @@ -123,12 +131,9 @@ export default defineConfig({
text: 'Roles',
link: '/config/authentication/roles',
},

{
text: 'OAuth',
link: '/config/authentication/oauth',
},
{
text: 'Custom methods',
text: 'Create custom methods',
link: '/config/authentication/customMethods',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export class EmailPassword
input,
context,
}: AuthenticationEventsOptions<EmailPasswordInterface>) {
// TODO : Use first here but need to refactor in graphql and mongoadapter to have first and not limit
const users = await context.wabe.controllers.database.getObjects({
className: "User",
where: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Default authentication methods

Wabe provides some default authentication methods that you can use in your project.

Here is a list of the default authentication methods:

- Email password
- Phone password
- Google

```graphql
# Email password
mutation signUpWith {
signUpWith(
input: {authentication: {emailPassword: {email: "your.email@gmail.com", password: "password"}}}
) {
id
accessToken
refreshToken
}
}
# Phone password
mutation signUpWith {
signUpWith(
input: {authentication: {phonePassword: {phone: "+33601020304", password: "password"}}}
) {
id
accessToken
refreshToken
}
}

#Google
mutation signUpWith {
signUpWith(
input: {authentication: {google: {authorizationCode: "authorizationCode", codeVerifier: "codeVerifier"}}}
) {
id
accessToken
refreshToken
}
}
```
17 changes: 15 additions & 2 deletions packages/wabe-documentation/docs/config/authentication/oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ const run = async () => {
const wabe = new Wabe({
// ... others config fields
authentication: {
successRedirectPath: "https://myapp.com/dashboard",
failureRedirectPath: "https://myapp.com/login",
session: {
cookieSession: true,
accessTokenExpiresInMs: 1000 * 60 * 15, // 15 minutes
refreshTokenExpiresInMs: 1000 * 60 * 60 * 24 * 7, // 7 days
},
backDomain: process.env.BACK_DOMAIN,
successRedirectPath: 'https://app.com/dashboard',
failureRedirectPath: 'https://app.com/signin',
roles: ['Admin', 'Client'],
providers: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID || '',
clientSecret: process.env.GOOGLE_CLIENT_SECRET || '',
},
},
},
});

Expand Down
8 changes: 4 additions & 4 deletions packages/wabe-documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "wabe-documentation",
"type": "module",
"scripts": {
"release": "bun docs:build && vercel docs/.vitepress/dist --prod",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs"
"release": "bun run build && vercel docs/.vitepress/dist --prod",
"dev": "vitepress dev docs",
"build": "vitepress build docs",
"preview": "vitepress preview docs"
},
"devDependencies": {
"vitepress": "1.5.0",
Expand Down
55 changes: 55 additions & 0 deletions packages/wabe/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum RoleEnum {
enum AuthenticationProvider {
google
emailPassword
phonePassword
}

enum SecondaryFactor {
Expand Down Expand Up @@ -54,10 +55,19 @@ type UserACLObjectRolesACL {
scalar Date

type UserAuthentication {
phonePassword: UserAuthenticationPhonePassword
emailPassword: UserAuthenticationEmailPassword
google: UserAuthenticationGoogle
}

type UserAuthenticationPhonePassword {
phone: Phone!
password: String!
}

"""Phone scalar type"""
scalar Phone

type UserAuthenticationEmailPassword {
email: Email!
password: String!
Expand Down Expand Up @@ -113,10 +123,16 @@ input UserACLObjectRolesACLInput {
}

input UserAuthenticationInput {
phonePassword: UserAuthenticationPhonePasswordInput
emailPassword: UserAuthenticationEmailPasswordInput
google: UserAuthenticationGoogleInput
}

input UserAuthenticationPhonePasswordInput {
phone: Phone!
password: String!
}

input UserAuthenticationEmailPasswordInput {
email: Email!
password: String!
Expand Down Expand Up @@ -170,10 +186,16 @@ input UserACLObjectRolesACLCreateFieldsInput {
}

input UserAuthenticationCreateFieldsInput {
phonePassword: UserAuthenticationPhonePasswordCreateFieldsInput
emailPassword: UserAuthenticationEmailPasswordCreateFieldsInput
google: UserAuthenticationGoogleCreateFieldsInput
}

input UserAuthenticationPhonePasswordCreateFieldsInput {
phone: Phone
password: String
}

input UserAuthenticationEmailPasswordCreateFieldsInput {
email: Email
password: String
Expand Down Expand Up @@ -712,12 +734,27 @@ input SearchWhereInput {
scalar Search

input UserAuthenticationWhereInput {
phonePassword: UserAuthenticationPhonePasswordWhereInput
emailPassword: UserAuthenticationEmailPasswordWhereInput
google: UserAuthenticationGoogleWhereInput
OR: [UserAuthenticationWhereInput]
AND: [UserAuthenticationWhereInput]
}

input UserAuthenticationPhonePasswordWhereInput {
phone: PhoneWhereInput
password: StringWhereInput
OR: [UserAuthenticationPhonePasswordWhereInput]
AND: [UserAuthenticationPhonePasswordWhereInput]
}

input PhoneWhereInput {
equalTo: Phone
notEqualTo: Phone
in: [Phone]
notIn: [Phone]
}

input UserAuthenticationEmailPasswordWhereInput {
email: EmailWhereInput
password: StringWhereInput
Expand Down Expand Up @@ -1147,10 +1184,16 @@ input UserACLObjectRolesACLUpdateFieldsInput {
}

input UserAuthenticationUpdateFieldsInput {
phonePassword: UserAuthenticationPhonePasswordUpdateFieldsInput
emailPassword: UserAuthenticationEmailPasswordUpdateFieldsInput
google: UserAuthenticationGoogleUpdateFieldsInput
}

input UserAuthenticationPhonePasswordUpdateFieldsInput {
phone: Phone
password: String
}

input UserAuthenticationEmailPasswordUpdateFieldsInput {
email: Email
password: String
Expand Down Expand Up @@ -1533,12 +1576,18 @@ input SignInWithInput {
}

input SignInWithAuthenticationInput {
phonePassword: SignInWithAuthenticationPhonePasswordInput
emailPassword: SignInWithAuthenticationEmailPasswordInput
google: SignInWithAuthenticationGoogleInput
otp: SignInWithAuthenticationOtpInput
secondaryFactor: SecondaryFactor
}

input SignInWithAuthenticationPhonePasswordInput {
phone: Phone!
password: String!
}

input SignInWithAuthenticationEmailPasswordInput {
email: Email!
password: String!
Expand All @@ -1564,12 +1613,18 @@ input SignUpWithInput {
}

input SignUpWithAuthenticationInput {
phonePassword: SignUpWithAuthenticationPhonePasswordInput
emailPassword: SignUpWithAuthenticationEmailPasswordInput
google: SignUpWithAuthenticationGoogleInput
otp: SignUpWithAuthenticationOtpInput
secondaryFactor: SecondaryFactor
}

input SignUpWithAuthenticationPhonePasswordInput {
phone: Phone!
password: String!
}

input SignUpWithAuthenticationEmailPasswordInput {
email: Email!
password: String!
Expand Down
Loading

0 comments on commit 2789dfd

Please sign in to comment.