Auth
OneDay.Build
uses NextAuth.js for user authentication. Here's how to configure it:
Set Environment Variables
In the .env
file, there is a section specifically for setting environment variables.
# ===============================================================
# Auth: https://docs.oneday.build/docs/features/Auth
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SECRET = ''
SECRET
can be set by entering the following command in the command line and using the returned value here.
openssl rand -base64 32
OAuth
Your platform can also use third-party platform accounts for login, such as Google or Github. You can click here to view the list of platforms supported by NextAuth and how to obtain Client ID and SECRET for each platform.
For example, for Google OAuth, click here for documentation
Fill in the information obtained from Google in the .env
file.
# ===============================================================
# Auth: https://docs.oneday.build/docs/features/Auth
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SECRET = ''
GOOGLE_CLIENT_ID =
GOOGLE_CLIENT_SECRET =
In your platform code, you can find the configuration file in app/api/auth/[...nextauth]/route.jsx
. Copy the code from OAuth there. The code provides default login methods for Github
, Google
, and username/password
.
If you encounter some problems during debugging, you can take a look at this article How to set up callback URLs on third-party platforms
Login Password and Recovery
OneDayBuild
also provides you with the option to use username and password for login. The corresponding files are:
- User Registration :
app/[locale]/(site)/(auth)/register
; - User Login :
app/[locale]/(site)/(auth)/login
; - Password Recovery :
app/[locale]/(site)/(auth)/change
;
You can find the code for these functionalities in the above paths, and adjust the pages according to your platform's style. It's worth noting that we also provide you with the complete code for password recovery, including:
- User inputs the email used for registration;
- If the email exists, the system sends a 4-digit verification code to the email email configuration;
- User opens the email and enters the verification code into the system;
- Verification succeeds, and the user enters a new password;
- Modification completed;
This process can also be a verification process for emails, so it is a necessary function for the basic platform.