main
rb 38 lines 1.11 KB
Raw
1 # frozen_string_literal: true
2
3 module Api
4 module V1
5 # Current-user profile and account removal for API clients.
6 class MeController < Api::BaseController
7 before_action :authenticate_token!
8
9 # GET /api/v1/me — returns User { id, email, created_at, updated_at }.
10 # Header: Authorization: Bearer <access_token>
11 def show
12 render json: user_profile_json, status: :ok
13 end
14
15 # DELETE /api/v1/me — permanently removes the smbCloud account and the
16 # local mirror. Returns 204 on success.
17 # Header: Authorization: Bearer <access_token>
18 def destroy
19 SmbcloudAuthService.remove(access_token: @access_token)
20 current_user.destroy
21 head :no_content
22 end
23
24 private
25
26 # The bare smbCloud profile, matching the desktop's `User` type.
27 def user_profile_json
28 p = @me_profile.respond_to?(:symbolize_keys) ? @me_profile.symbolize_keys : @me_profile
29 {
30 id: p[:id],
31 email: p[:email],
32 created_at: p[:created_at],
33 updated_at: p[:updated_at]
34 }
35 end
36 end
37 end
38 end